[9182] in Perl-Users-Digest
Perl-Users Digest, Issue: 2799 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 3 17:07:26 1998
Date: Wed, 3 Jun 98 14:00:30 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 3 Jun 1998 Volume: 8 Number: 2799
Today's topics:
Re: "system" output redirect (Tad McClellan)
Re: Best tool? <stuartc@ind.tansu.com.au>
Blocking variables from a CGI <crosscountry@mindspring.com>
Re: Comm.pl (Mike D. Kail)
Fun with two arrays (Daniel)
Re: Fun with two arrays <jdporter@min.net>
GIFgraph problems <jurgen@pallas.tid.es>
HELP! Parsing text files for tables sfynn@my-dejanews.com
Re: how can I invoke concurrent perl processes in win-N (Jonathan Stowe)
Re: How do I tell if Perl is in foreground or backgound <stuartc@ind.tansu.com.au>
Re: Incrementing zero-padded numbers (Mark-Jason Dominus)
Re: Incrementing zero-padded numbers (Jonathan Stowe)
Re: Incrementing zero-padded numbers (Tad McClellan)
Re: Incrementing zero-padded numbers pehanna@my-dejanews.com
Re: Incrementing zero-padded numbers <zenin@bawdycaste.org>
Re: map in void context regarded as evil - suggestion (Abigail)
Re: Perl class for newbie? suave@colba.net
Perl DBI + Postgres? (Nick Carter)
question re: sytanx for interpolation of obj->method in Matthew.Wickline@usa.net
Re: regex help. ptimmins@netserv.unmc.edu
Re: regex help. (Tad McClellan)
Re: removing lines (delete regexp) (Mark-Jason Dominus)
setting a uid <hilljere@pilot.msu.edu>
Specialized Split (Jeffrey Horn)
Spider programms in PERL <arcadiev@usa.net>
Re: Spider programms in PERL (Jonathan Stowe)
Re: study; (Mark-Jason Dominus)
Re: study; (Mark-Jason Dominus)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 3 Jun 1998 15:09:01 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: "system" output redirect
Message-Id: <tga4l6.0u5.ln@localhost>
Gabriel Climescu (gclim@NOSPAM.nt.com) wrote:
: I was able to find this perlfaq8 (well, it would have been easier to
: mention a place where to find it
OK.
Let's mention where the Perl FAQs are (yet again).
They are *already on your hard disk*!!
They *come with* Perl.
If you have a perl distribution of little brain,
(ie. with the documentation lobotomized) then dump it,
and get a real perl.
Doesn't the auto-email for first time posters tell where to get
the Perl FAQs.
Did you even read that email?
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 03 Jun 1998 11:02:48 +1000
From: Stuart Cooper <stuartc@ind.tansu.com.au>
Subject: Re: Best tool?
Message-Id: <yeobtsbcn5z.fsf@kudu.ind.tansu.com.au>
Randal Schwartz <merlyn@stonehenge.com> writes:
> What's "X Windows"? Is that like "Microsoft Windows"?
> I've heard of "X", "X11", and "the X Window System". But never "X Windows".
> I've seen "X" put up "windows", so I'd call those "X windows", but not
> "X Windows".
> :-)
I think 'X Windows' is OK usage; I'll go along with Zenin here.
It might make some managers more intersted in Unix. :)
> (I've even hung up the phone on a recruiter once because he called me
> to see if I could program "X Windows", and I said "no such thing" and
> he didn't get it. Stoopid recruiter. :-)
I was once asked by a similarly stupid recruiter if I knew the ASC2 format.
Her knowledge of Roman Numerals was better than her understanding of
the computing industry. One of Australia's best known rock music presenters
once held up an album by a band he described as "E equals M C two".
Perhaps some readers have amusing stories of the knowledge of Perl in the
recruitment world they can share with us.
Cheers,
Stuart.
------------------------------
Date: 3 Jun 1998 19:39:19 GMT
From: "Eric M. Klein" <crosscountry@mindspring.com>
Subject: Blocking variables from a CGI
Message-Id: <01bd8f27$5d7b4c60$c8b956d1@crosscountry.mindspring.com>
Hello,
My name is Eric Klein and I am the Internet Developer for Cross Country
Staffing. I'm not much of a Perl hacker. However, I have found a need to
modify a script (namely Matt's FormMail) to suit my needs. I'm attempting
to get FormMail to write certain variables into the email, and leave out
certain specified ones. I'll include the routine below. As you can see, I'm
trying to accomplish this by a while loop (i.e., while x is not equal to y,
do this). Anyway, I'm coming up on a deadline, and I have no clue why this
doesn't work. Any ideas? Thanks in advance!
Eric M. Klein, Webmaster
Cross Country Staffing
crosscountry@mindspring.com
P.S. Look about halfway down in the script to see what I'm trying to do.
Line starts with #otherwise. The variables I'm trying to block from being
emailed are
zaxus,ccs, and yahoo. Thanks again!
Attached Perl Script
-------------------------------------
sub send_mail {
# Localize variables used in this subroutine.
#
local($print_config,$key,$sort_order,$sorted_field,$env_report);
# Output a temporary file
open(MAIL,">$tempdir\\tempfile") || die("Cannot open $tempdir\\tempfile
-- Check Directory Permissions : $!");
print MAIL "To: $Config{'recipient'}\n";
print MAIL "From: $Config{'email'} ($Config{'realname'})\n";
# Check for Message Subject
if ($Config{'subject'}) { print MAIL "Subject: $Config{'subject'}\n\n"
}
else { print MAIL "Subject: WWW Form Submission\n\n"
}
print MAIL "Below is the result of your feedback form. It was
submitted by\n";
print MAIL "$Config{'realname'} ($Config{'email'}) on $date\n";
print MAIL "-" x 75 . "\n\n";
if (@Print_Config) {
foreach $print_config (@Print_Config) {
if ($Config{$print_config}) {
print MAIL "$print_config: $Config{$print_config}\n\n";
}
}
}
# Sort alphabetically if specified:
#
if ($Config{'sort'} eq 'alphabetic') {
foreach $field (sort keys %Form) {
# If the field has a value or the print blank fields option #
# is turned on, print out the form field and value. #
if ($Config{'print_blank_fields'} || $Form{$field} ||
$Form{$field} eq '0') {
print MAIL "$field: $Form{$field}\n\n";
}
}
}
# If a sort order is specified, sort the form fields based on that.
#
elsif ($Config{'sort'} =~ /^order:.*,.*/) {
# Remove extraneous line breaks and spaces, remove the order: #
# directive and split the sort fields into an array. #
$Config{'sort'} =~ s/(\s+|\n)?,(\s+|\n)?/,/g;
$Config{'sort'} =~ s/(\s+)?\n+(\s+)?//g;
$Config{'sort'} =~ s/order://;
@sorted_fields = split(/,/, $Config{'sort'});
# For each sorted field, if it has a value or the print blank #
# fields option is turned on print the form field and value. #
foreach $sorted_field (@sorted_fields) {
if ($Config{'print_blank_fields'} || $Form{$sorted_field} ||
$Form{$sorted_field} eq '0') {
print MAIL "$sorted_field: $Form{$sorted_field}\n\n";
}
}
}
# Otherwise, default to the order in which the fields were sent.
#
else {
# For each form field, if it has a value or the print blank #
# fields option is turned on print the form field and value. #
foreach $field (@Field_Order) {
while ($field ne 'zaxus' || 'yahoo' || 'ccs') {
if ($Config{'print_blank_fields'} || $Form{$field} ||
$Form{$field} eq '0') {
print MAIL "$field: $Form{$field}\n\n";
}
}
}
}
print MAIL "-" x 75 . "\n\n";
# Send any specified Environment Variables to recipient.
#
foreach $env_report (@Env_Report) {
if ($ENV{$env_report}) {
print MAIL "$env_report: $ENV{$env_report}\n";
}
}
close (MAIL);
#'use' the process module.
use Win32::Process;
#theWin32:: module. Includes the Win32 error checking etc.
# see Win32:: section for included functions.
use Win32;
sub Error{
print Win32::FormatMessage( Win32::GetLastError() );
}
#Create the process object.
Win32::Process::Create($ProcessObj, $mailprog, "Blat
$tempdir\\tempfile -t $Config{'recipient'} -s \"$Config{'subject'}\" -f
$Config{'email'} -i \"$Config{'email'}
($Config{'realname'})\"", 0, DETACHED_PROCESS, ".")|| die &Error;
#Set the process priority
#$ProcessObj->SetPriority(NORMAL_PRIORITY_CLASS)||die &Error;
#Wait for the process to end. NO timeout
$ProcessObj->Wait(0);
#open(MAIL,"|$mailprog $tempdir\\tempfile -t $Config{'recipient'} -s
\"$Config{'subject'}\" -i \"$Config{'email'} ($Config{'realname'})\" -f
$Config{'email'}") ||
die("Cannot execute $mailprog -- Check mailprog path and permissions :
$!");
#close(MAIL);
if ($uselog eq '1') {
&log('entry');
}
}
------------------------------
Date: 3 Jun 1998 18:44:52 GMT
From: mdkail@fv.com (Mike D. Kail)
Subject: Re: Comm.pl
Message-Id: <slrn6nb6m8.64f.mdkail@dime.fv.com>
On Wed, 03 Jun 1998 16:23:48 GMT, kin <kin@c-cube.com> wrote:
>Hi,
>I'm looking for examples of how to use the expect() function
>in this package I found on CPAN.
>
>Specifically, say I want to programmatically run "su foo".
>I want to do something like this:
>
>open(SU,'|su foo|');
>
>(...) = expect(SU,...);
>
>But bidirectional pipes aren't supported in Perl!
% perldoc IPC::Open2
[...]
DESCRIPTION
The open2() function spawns the given $cmd and connects $rdr
for reading and $wtr for writing. It's what you think
should work when you try
open(HANDLE, "|cmd args|");
--
/*-------------------------------------------------------------*/
/* Mike D. Kail | voice: (619) 350-3524 */
/* Unix System Architect | fax: (619) 793-2950 */
/* FIRST VIRTUAL Holdings Inc. | e-mail: mdkail@fv.com */
/*-------------------------------------------------------------*/
------------------------------
Date: 3 Jun 1998 18:58:04 GMT
From: daniel.mendyke@digital.com (Daniel)
Subject: Fun with two arrays
Message-Id: <6l46bs$389$1@nntpd.lkg.dec.com>
Given:
my @first = qw( one two three four );
my @second = qw( mon tue wed thr );
What is the quickest way to produce a thrid
array such that it contains
"one mon two tue three wed four thr"?
my @third = ????
Daniel Mendyke
==============================================
daniel@virtualvoices.com
Sell it OnLine at http://www.virtualvoices.com
==============================================
------------------------------
Date: Wed, 03 Jun 1998 19:10:14 GMT
From: John Porter <jdporter@min.net>
Subject: Re: Fun with two arrays
Message-Id: <3575A142.436A@min.net>
Daniel wrote:
>
> Given:
>
> my @first = qw( one two three four );
> my @second = qw( mon tue wed thr );
>
> What is the quickest way to produce a thrid
> array such that it contains
> "one mon two tue three wed four thr"?
>
> my @third = ????
my @third = qw( one mon two tue three wed four thr );
But that might be a little hard-coded for most purposes.
If I can assume that @first and @second always have the
same number of elements, then:
my @third = map { ( $first[$_], $second[$_] ) } 0..$#first;
If not, then I can only guess what behavior you want.
One way would be:
my @third;
while ( @first or @second ) {
push( @third, shift @first ) if @first;
push( @third, shift @second ) if @second;
}
Another:
my @third = map { ( $first[$_], $second[$_] ) }
0..( @first > @second ? $#first : $#second );
# raises some warnings under -w
There are, of course, many other ways.
hth,
John Porter
------------------------------
Date: Wed, 03 Jun 1998 21:32:33 +0200
From: Jurgen Koeleman <jurgen@pallas.tid.es>
Subject: GIFgraph problems
Message-Id: <3575A4D1.EE0535E@pallas.tid.es>
I am using the module GIFgraph to display GIF output for a graph, but
have a problem with it and don't know how to solve it.
I want to use the ticks on the X-axis, but not for each data point.
E.g. for all the minutes of the day there is a data point, but the
ticks are only needed once every 60 minutes.
I was suggested to use the parameter x_label_skip=60, but
unfortunately this does not solve my problem. x_label_skip only
affects the labels that can be placed with the ticks, but not the
ticks themselves.
Maybe the following simplified example shows what I mean:
====================
#!/usr/bin/perl
use GIFgraph::lines;
@data = (
[ undef, undef, "1", undef, undef, "2", undef, undef, "3" ],
[ 1 , 3 , 2 , 5 , 1 , 4 , 2 , 1 , 3 ]
);
$g = new GIFgraph::lines();
$g->set(
'x_ticks' => 1,
'tick_length' => 6,
'x_label_skip' => 1,
'x_plot_values' => 1,
);
$g->plot_to_gif("/tmp/plotfile", \@data);
system("xv /tmp/plotfile");
unlink("/tmp/plotfile");
exit 0;
====================
The only values on the X-axis are 1, 2 and 3. Only at these data
points a tick should be a plotted, not at the intermediate data
points (where the value for the X-axis is undef). However, each
points results in a tick on the X-axis.
Any idea how to solve this problem?
All suggestions are welcome.
Thanks in advance,
Jurgen Koeleman
------------------------------
Date: Wed, 03 Jun 1998 20:42:41 GMT
From: sfynn@my-dejanews.com
Subject: HELP! Parsing text files for tables
Message-Id: <6l4cg1$c5t$1@nnrp1.dejanews.com>
I need to parse news releases (formatted text files) which sometimes have
tabular data in them. I need to place this data into a Foxpro database, which
is no problem, except that there is no normal format for these tables. Some
are delineated by spaces, some tabs, some made pretty with ASCII.. So my
problem is that I can't detect when data is actually a table or not.
If anyone could direct me to resources or products that would help with this
situation, it would be much appreciated.
Scott Fynn
Market News Publishing
Vancouver, BC
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: Wed, 03 Jun 1998 19:38:02 GMT
From: Gellyfish@btinternet.com (Jonathan Stowe)
Subject: Re: how can I invoke concurrent perl processes in win-NT
Message-Id: <35759e9e.8351126@news.btinternet.com>
On Wed, 03 Jun 1998 10:57:35 -0700, hoang uong wrote :
>Hi,
>I use cygnus bash shell in Win-NT 3.51.
>I intend to invoke perl script 'script_name' multiple times in the
>background (I use '&' as in Unix). The following code
>does not work
>for( $i = 0; $t < 3; $i+= ){
> system("perl script_name param1 param2 &");
>}
>
This is presumably because system is using a command interpreter other
than bash if it is using one at all (probably cmd.exe). You can get
around this in a number of ways
* Change the default command interpreter by the use of the appropriate
environment setting
* Run your script with the "start" command with the appropriate
switches .
* Use Win32::CreateProcess to create detached processes.
/J\
Jonathan Stowe
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
------------------------------
Date: 03 Jun 1998 10:35:29 +1000
From: Stuart Cooper <stuartc@ind.tansu.com.au>
Subject: Re: How do I tell if Perl is in foreground or backgound?
Message-Id: <yeod8crcofi.fsf@kudu.ind.tansu.com.au>
Robert Dorfman <dorfmanr@netlabs.net> writes:
> This is a multi-part message in MIME format.
> --------------A44C4B90A9E97C65F6E684B2
> Content-Type: text/plain; charset=us-ascii
> Content-Transfer-Encoding: 7bit
>
> I have a Perl/Sybperl script that logs into a Sybase Adaptive Server
> and starts a database backup. This is run automatically by cron.
> However, I'd like to use the same script and allow it to be called by a
> user.If running in the foreground I'll display a list of databases that
> may be selected for backup. Then I'll fork the process to do the actual
> database dump. How can I tell if my script is running in foreground or
> background? Also, would running in the background be different from
> being started by cron?
>
> Thanks.
> Robert Dorfman
> --------------A44C4B90A9E97C65F6E684B2
> Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf"
[vcard snipped]
> Tom Phoenix writes:
> I'm not certain, but you may want the -t filetest, which tells you whether
> a filehandle is open to a tty (roughly, something which will type to you,
> as opposed to a file). Hope this helps!
Tom's on the right track as usual. You want the the -t tests on STDIN and
STDOUT; this tells you whether these are directed to a tty.
Small program:
#! /usr/local/bin/perl -w
if (-t STDIN) {
print "TTY Input\n";
} else {
print "Input redirected\n";
}
if (-t STDOUT) {
print "TTY Output\n";
} else {
print "Output redirected\n";
}
If STDIN is not TTY; you can consider the program to be non-interactive.
If STDOUT is not TTY; but STDIN is; it's a confusing setup whereby the
user won't see anything. This scenario is unusual.
There's no way I know of to see if a program was run in background.
Basically, if I run
$ job.pl < infile then STDIN is redirected
$ job.pl > job.out then STDOUT is redirected
$ job.pl < infile > job.out then STDIN and STDOUT is redirected
but I *don't* know if it's
$ job.pl (redirections) &
or just
$ job.pl (redirections)
There's slight differences between running something through cron and
straight background. cron will redirect and mail STDOUT to you if you don't
specifically do it yourself. (which is why you can use the -t STDOUT test to
see if it might be running as a cron job). cron does not inherit your
environment, working directory etc. Apart from that; which you need to be
careful of otherwise it will bite you; cron is like a background job with
the input and output both redirected.
The STDIN for a cron job is usually /dev/null; but can be specified by stuff
in %'s in the crontab entry; eg: /etc/wall%Happy New Year%Have a good one!.
Finally, in the case of your script, you probably want to check that the
databases aren't already being backed up by another running instance of
the script.
Hope this helps.
Stuart Cooper
stuartc@ind.tansu.com.au
------------------------------
Date: 3 Jun 1998 14:56:19 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Incrementing zero-padded numbers
Message-Id: <6l468j$874$1@monet.op.net>
Keywords: appraise canvasback respire Scotsman
In article <slrn6nb0l1.nnl.andyc@worf.netins.net>,
Andy Chandler <andyc@netins.net> wrote:
>I want to create a series of files based on incrementing zero-padded
>numbers. For example, if I have the number 0001, I want to automatically
>increment to 0002.
You use the increment operator for that.
# TRY ME
$q = '0001';
for (;;) {
$q++; # Increment
print $q, "\n";
}
------------------------------
Date: Wed, 03 Jun 1998 19:38:03 GMT
From: Gellyfish@btinternet.com (Jonathan Stowe)
Subject: Re: Incrementing zero-padded numbers
Message-Id: <3575a297.9151273@news.btinternet.com>
On 3 Jun 1998 17:06:41 GMT, Andy Chandler wrote :
>Hi all, looking for some help...
>
>I want to create a series of files based on incrementing zero-padded
>numbers. For example, if I have the number 0001, I want to automatically
>increment to 0002. I've got the incrementing numbers down (1,2,3,etc),
>but I need to know how to do it ith the zero-padded numbers.
>
To summarize:
#!perl
$theno = 1;
for(1 ... 10)
{
$out = sprintf("%04d",$theno++);
print $out,"\n";
}
That looks alright.
But wait ! Whats this:
#!perl
$theno = "0001";
for(1 ... 10)
{
$out = $theno++;
print $out,"\n";
}
Magical autoincrement !!
/J\
Jonathan Stowe
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
------------------------------
Date: Wed, 3 Jun 1998 14:55:31 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Incrementing zero-padded numbers
Message-Id: <jn94l6.0u5.ln@localhost>
Andy Chandler (andyc@netins.net) wrote:
: Hi all, looking for some help...
: I want to create a series of files based on incrementing zero-padded
: numbers. For example, if I have the number 0001, I want to automatically
: increment to 0002. I've got the incrementing numbers down (1,2,3,etc),
: but I need to know how to do it ith the zero-padded numbers.
$num = 2;
$padded = sprintf "%04d", $num;
print "$padded\n";
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 03 Jun 1998 20:29:22 GMT
From: pehanna@my-dejanews.com
Subject: Re: Incrementing zero-padded numbers
Message-Id: <6l4bn1$arj$1@nnrp1.dejanews.com>
> I want to create a series of files based on incrementing zero-padded
> numbers. For example, if I have the number 0001, I want to automatically
> increment to 0002. I've got the incrementing numbers down (1,2,3,etc),
> but I need to know how to do it ith the zero-padded numbers.
Incrementing is incrementing; what you really want to know is "how do I pad a
number with leading zeros?":
$npadded = sprintf("%04d", $n);
--
Phil Hanna
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: 3 Jun 1998 20:50:51 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: Incrementing zero-padded numbers
Message-Id: <896907556.218684@thrush.omix.com>
Andy Chandler <andyc@netins.net> wrote:
: I want to create a series of files based on incrementing zero-padded
: numbers. For example, if I have the number 0001, I want to automatically
: increment to 0002. I've got the incrementing numbers down (1,2,3,etc),
: but I need to know how to do it ith the zero-padded numbers.
Pad *after* you increment.
for (my $i=0; $i <= 9999; $i++) {
my $filename = sprintf ('foobar.%04d', $i);
open SESAME, ">$filename"
or die $!;
...stuff...
}
--
-Zenin
zenin@archive.rhps.org
------------------------------
Date: 3 Jun 1998 19:34:21 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: map in void context regarded as evil - suggestion
Message-Id: <6l48ft$2c3$2@client3.news.psi.net>
Michael J Gebis (gebis@albrecht.ecn.purdue.edu) wrote on MDCCXXXVII
September MCMXCIII in <URL: news:6l4285$q5f@mozo.cc.purdue.edu>:
++
++ Way back when I was an undergrad and the web was new, I seem to
++ remember the utter simplicity of turning a document into HTML. All
++ one had to do was throw a bracketed P at the end of every paragraph,
++ and you were done.<P>
++
++ Of course, things being the way they were, people wanted <I>change</I>
++ and <B>progress</B>. <A HREF="about:marca">Marc</A> added <IMG
++ SRC="http://people.netscape.com/marca/marca.gif"> images, which of
++ course violated a standard few people knew existed. After all, HTML
++ is really just a DTD for SGML. Out came the pedants, who decided that
++ HTML needed rules, which of course meant that everyone lobbied for
++ their favorite feature and the HTML standard, instead of evolving in the
++ market, was designed by committee.<P>
If only HTML was designed by a committee. BLINK, FONT, BGCOLOR, etc, are
all "inventions" from the evil empire - Netscape Communication Corporation.
And they don't believe in standards.
As for paragraphs being containers - that's follows from HTML being defined
with SGML rules. The decision to move HTML towards SGML was proposed by
Dan Conolly, back in 1992 or so.
Abigail
--
perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'
------------------------------
Date: Wed, 03 Jun 1998 16:05:52 -0400
From: suave@colba.net
Subject: Re: Perl class for newbie?
Message-Id: <3575ACA0.C0EED0CF@colba.net>
>
> Tom Phoenix wrote:
> >
> > On Mon, 1 Jun 1998, Dan Franco wrote:
> >
> > > Can anyone recommend a good Perl course for a non programmer? Perhaps
> > > something that teaches the basics of Perl along with general
> > > programming concepts?
> >
I suggest the Llama book (Learning Perl, by Randal Schwartz and Tom
Christiansen, published by O'Reilly). It's an amazing book, and will
teach you the basics about programming perl, with this you should be
able to pick up the basic concepts of programming as well as get a good
feel for perl. Beware, you might have to spend a good deal of time when
you first start out, but it gets easier as you get further into the
book.
Mark Steele
Technical Support Supervisor
ColbaNet Internet Inc.
Montreal, Quebec
------------------------------
Date: Wed, 3 Jun 1998 20:26:22 GMT
From: ap874@torfree.net (Nick Carter)
Subject: Perl DBI + Postgres?
Message-Id: <Etzsrz.6Ap.0.bloor@torfree.net>
Hello,
Does anyone have experience with running Perl DBI as an interface to the
Postgres RDBMS? I can get Postgres running fine by itself, but for some
reason, when I try to use Perl's DBI to talk to it, I am not getting too
much luck. Basically I get errors when I do a call such as:
DBI->install_driver("Pg"); or
DBI->connect(..., ..., ...);
Talking of Postgres, is it worth wasting my time with it? or should I just
get Oracle instead?
I would appreciate any email from you regarding your opinion/pointers, helps.
Thanks
------------------------------
Date: Wed, 03 Jun 1998 20:41:05 GMT
From: Matthew.Wickline@usa.net
Subject: question re: sytanx for interpolation of obj->method in qq context
Message-Id: <6l4cd1$c5b$1@nnrp1.dejanews.com>
please cc via email. thx :)
In the past, the following two types of print commands have given me identical
results. Is this a freakish coincidence of the particular circumnstance, or
*should* they return identical results?
$obj->data("this is data!\n");
print "${\$obj->data}";
my $foo = $obj->data; print $foo;
I ask because I now find myself in a situation where the first sort of syntax
no longer seems to work: it prints "2" w/o a \n. I can get the longer-winded
way (with the temp variable) to work, but I always thought the first way
should work.
Have I been incorrect all along with the first way, or is there some problem
I need to isolate which is interfering in this single instance?
-matt
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: Wed, 03 Jun 1998 19:28:21 GMT
From: ptimmins@netserv.unmc.edu
Subject: Re: regex help.
Message-Id: <6l484k$5dj$1@nnrp1.dejanews.com>
In article <6l40sc$q9p$1@nnrp1.dejanews.com>,
bthak@bascom.com wrote:
>
> Need some help.
>
> $temp = shift;
>
> if ($temp =~ /[a-zA-Z_0-9]{8,}/){
> if ($temp =~ /\d{2,3}/) {
> print "good has 8 chars and 2-3 number";
> }
> else {
> print "8 chars but needs to have numbers";
> }
> }
> else {
> print "not eight chars";
> }
>
> "($temp =~ /\d{2,3})" <-- checks for consecutive digit how can i have it so
> something like 1blahblah1 will be a match.
>
The following works. Notice that I used the \w in the first match which is
equivalent to [a-zA-Z_0-9]. It is the /\D*\d\D*\d/ that fixes the problem:
$temp = shift;
if ($temp =~ /[\w]{8,}/){
if ($temp =~ /\D*\d\D*\d/) {
print "good has 8 chars and 2-3 number";
}
else {
print "8 chars but needs to have numbers";
}
}
else {
print "not eight chars";
}
Note, however that this matches words that have 2 or more digits, not just 2
or 3.
Patrick Timmins
U. Nebraska Medical Center
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: Wed, 3 Jun 1998 15:02:10 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: regex help.
Message-Id: <24a4l6.0u5.ln@localhost>
bthak@bascom.com wrote:
: Need some help.
: $temp = shift;
: if ($temp =~ /[a-zA-Z_0-9]{8,}/){
^^^^^^^^^^^^
^^^^^^^^^^^^
You could replace all of that with two characters, you know...
if ($temp =~ /\w{8,}/){ # same as above, but easier to understand
[snip]
: "($temp =~ /\d{2,3})" <-- checks for consecutive digit how can i have it so
: something like 1blahblah1 will be a match.
$temp =~ /\d.*\d/; # match if has two digit characters
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 3 Jun 1998 15:30:07 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: removing lines (delete regexp)
Message-Id: <6l487v$8ja$1@monet.op.net>
Keywords: commodity flatware grandchild pagan
In article <35756D58.ABF2DCE@fleaflicker.com>,
Dave Jackson <porkchop@fleaflicker.com> wrote:
>i get errors when i try:
>/BOB/d;
>trying to delete all BOBs from my file
Yeah, well, that's because the /d regex modifier isn't implemented
yet. It's scheduled to appear in Perl 5.028b, which should be
released in autumn of 2023.
Who told you about it, by the way? It was supposed to be a secret.
Try this:
perl -i.bak -ne 'print if /./' FILE1 FILE2 FILE3 ...
You might also want to look at the section of the FAQ that says
``How do I change one line in a file/delete a line in a
file/insert a line in the middle of a file/append to the
beginning of a file?"
Look for `perlfaq5' on your system.
------------------------------
Date: Wed, 03 Jun 1998 15:37:04 -0400
From: Jeremy Hill <hilljere@pilot.msu.edu>
Subject: setting a uid
Message-Id: <3575A5E0.9DA12977@pilot.msu.edu>
Hello all,
Does anyone know how I could conveniently
change uid's in a script that runs as root, such as
foreach $user (@users) {
change_uid($user); #(imaginary function)
#do stuff as this user...
change_uid(back to root);
}
Thanks for any ideas!!!!
-Jeremy Hill
------------------------------
Date: 3 Jun 1998 20:05:22 GMT
From: horn@beaner.cs.wisc.edu (Jeffrey Horn)
Subject: Specialized Split
Message-Id: <6l4aa2$h9i@spool.cs.wisc.edu>
I am looking for a slick way to split on a given character/pattern
only if that character/pattern does not fall between opening and closing
parens.
Thus if I were to split on /\+\-/
(1-3)+(2+5)
would only split into two elements:
(1-3)
(2+5)
Not the four elements as a normal split would
(1
3)
(2
5)
I can think of a few ways of doing this, but none are really elegant!
1.) Go through character by character keeping track of paren counts
2.) split with a noremal split and then past elements together that
don't have equal numbers of open and close parens.
Anyone have a slick solution?
-- Jeff Horn
--
Jeffrey Horn (horn@cs.wisc.edu) |BELZER,BERNHARDT,BOETTCHER,DRAVIS,FETTER
PHONE:(608) 244-8420 |GAPINSKI,GAUGER,HARMS,HIRSCHINGER,HORNE
FAX: (608) 221-5008 |JUECH,KLAJBOR,KROIS,KRONING,LEMKE,RUNGE
http://www.cs.wisc.edu/~horn/horn.html |STOCK,TAUBERT,TRESKE,WILLMERT,ZILLMER
------------------------------
Date: Wed, 03 Jun 1998 20:36:04 GMT
From: "Leonid A.Arcadiev" <arcadiev@usa.net>
Subject: Spider programms in PERL
Message-Id: <01bd8f26$fa78ec80$e8854018@dundas>
Can anybody advice how to write a spider in perl, that would check on a
website and read through its contents. If the responce has been received,
everything is fine, if no responce, generate an error message.
Please post a reply or send it to arcadiev@usa.net
Many thanks in advance,
Sincerely,
L.A.Arcadiev
------------------------------
Date: Wed, 03 Jun 1998 20:46:20 GMT
From: Gellyfish@btinternet.com (Jonathan Stowe)
Subject: Re: Spider programms in PERL
Message-Id: <3575afe6.12244649@news.btinternet.com>
On Wed, 03 Jun 1998 20:36:04 GMT, Leonid A.Arcadiev wrote :
> Can anybody advice how to write a spider in perl, that would check on a
>website and read through its contents. If the responce has been received,
>everything is fine, if no responce, generate an error message.
> Please post a reply or send it to arcadiev@usa.net
>
Hmm theres a real vogue for this stuff right at this moment.
There was a recent thread on something similar here:
Subject: cron job via perl ??
From: Kerem Yaman <kyaman@earthlink.net>
Date: 1998/05/27
Message-ID: <356CE415.4E0F9861@earthlink.net>
Newsgroups: comp.lang.perl.misc
which can be found on DejaNews.
Now if you do decide to use HTML::Parser for your purposes you will
probably want to collect the value of the HREF attribute for each A
tag you find in your start() subroutine into an array over the
contents of which you will loop to open each page in turn.
That all said you might want to check out MOMspider at:
http://www.ics.uci.edu/pub/websoft/MOMspider/
As there are other considerations such as Robot Exclusion and so on
that ought to be considered.
/J\
Jonathan Stowe
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
------------------------------
Date: 3 Jun 1998 15:09:11 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: study;
Message-Id: <6l470n$8aj$1@monet.op.net>
Keywords: Bologna Haydn Hickey thrive
In article <896881231.963828@thrush.omix.com>,
Zenin <zenin@bawdycaste.org> wrote:
> $num++ while ($card =~ /\b$keyword/i);
I think you wanted to say
> $num++ while ($card =~ /\b$keyword/ig);
there. Otherwise it's an infinite loop.
------------------------------
Date: 3 Jun 1998 15:25:00 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: study;
Message-Id: <6l47uc$8gj$1@monet.op.net>
Keywords: disputant geriatric teaspoonful Waller
In article <35759CC0.72CA@cardiff.ac.uk>,
Dean Jenkins <jenkinsrd@cf.ac.uk> wrote:
>I'd like to speed up the following search using study.
You use `study' when you're going to do many pattern matches on the
same string. That doesn't fit what you're doing here.
To use `study', you'd need to turn the loops inside out:
foreach $card (@lines) {
study $card;
# $card is now ready for many pattern matches.
foreach $keyword (@words) {
# etc.
}
}
In this case, though, I'd recmomend a different approach: Search for
all the keywords simultaneously. We'll construct a pattern that will
match *any* keyword, like this:
$KEYWORD_PAT = join '|', @words;
Then we can match a card against this one pattern instead of doing
20-40 matches against different patterns. That's a lot faster that
what you were doing:
$KEYWORD_PAT = join '|', @words;
foreach $card (@lines) {
my ($first_line, $rest) = split '|', $card, 2;
my ($keyword_count, $first_line_keyword_count) = (0, 0);
$first_line_keyword_count++ while $first_line =~ /\b($KEYWORD_PAT)/ogi;
$keyword_count++ while $rest =~ /\b($KEYWORD_PAT)/ogi;
$meds{$card} = $first_line_keyword_count * 15 + $keyword_count;
}
Regular expression matching has two phases: The regex is compiled,
and then it is run. Running it is fairly efficient, but compiling is
relatively slow. Usually, perl compiles every regex only once, at the
time you start your program. But if the regex contains variables, it
has to recompile the regex every time it wants to do a match. In
your program, this results in about 100,000 compilations.
If you can arrange that the regex never changes, you can put the /o
modifier on it. The /o is a promise to Perl that the variable
$KEYWORD_PAT will not change. Perl responds to this by compiling the
regex once only, instead of every time it does a match. The result is
that we have 2 regex compilations instead of 100,000.
$count++ while $string =~ /pattern/g;
is a useful idiom for counting the number of occurrences of something.
The /g tells Perl to find a different match every time. If you
omitted it; Perl would increment $count forever, finding the same
match over and over.
If you wanted to try `study' here, you could insert it right after the
`foreach'. I don't know if it would help or not. Try it both ways
and see.
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V8 Issue 2799
**************************************