[22835] in Perl-Users-Digest
Perl-Users Digest, Issue: 5056 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 29 11:06:02 2003
Date: Thu, 29 May 2003 08:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 29 May 2003 Volume: 10 Number: 5056
Today's topics:
Re: [PE] - Cerco Perl e PerlCgi con manuale in italian (Anno Siegel)
A bug in perl? <mordor@fly.srk.fer.hr>
Re: A bug in perl? (Tad McClellan)
Re: A bug in perl? (Anno Siegel)
Re: Bioperl? (Anno Siegel)
Re: Bioperl? ctcgag@hotmail.com
Re: copying files to another directory <me@privacy.net>
Re: hard time with regexp to validate image <recycle@bin.com>
Help Needed Building Packet <dreq@earthlink.net>
How can I get XML::RSS? (ActivePerl) <singleantler-news@hotmail.com>
Image::Grab query (Tom Cutting)
Piping STDOUT to sendmail via a perl script <dillon@SpamMinuSaccessdenied.darktech.org>
Re: Q about assignments for unmatched regex <michael@trollope.org>
Re: regular expression matches but $1 left undefined <john.thetenant-s@moving-picture.com>
Re: regular expression matches but $1 left undefined <g4rry_short@zw4llet.com>
Re: regular expression matches but $1 left undefined <g4rry_short@zw4llet.com>
Re: regular expression matches but $1 left undefined (Tad McClellan)
Re: Semi-Newbie Steps Into Module Hell <kevin.vaughn@ttu.edu>
Re: Tempopary files on Win32 <recycle@bin.com>
Re: uninitialized value in eval block? <spam.me.senseless@sitting.duck>
Re: uninitialized value in eval block? <spam.me.senseless@sitting.duck>
Re: uninitialized value in eval block? <tassilo.parseval@rwth-aachen.de>
Re: uninitialized value in eval block? <w.koenig@acm.org>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 29 May 2003 13:58:18 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: [PE] - Cerco Perl e PerlCgi con manuale in italiano in ambiente windows 98 o 2000 da scaricare
Message-Id: <bb53lq$qir$1@mamenchi.zrz.TU-Berlin.DE>
Romolo Cappola <rcappola@webzone.it> wrote in comp.lang.perl.misc:
>
> Ho installato una specie di Web Server con Apache 2.0.43 su windows 98
> che mi funziona.
> Ho installato un Php e un Mysql
> Mi manca Perl Cgi e le istruzioni per settare bene Php, MySql e Perl
> Lo scopo è di realizzare un piccolo negozio elettronico e provarlo.
> Conosco abbastanza bene il linguaggio Sql Oracle Lite.
> Mi farebbe comodo una dritta.
Google for "perl italian". Some hits indicate there was an effort to
translate Perl documentation to Italian, though I don't know what has
become of it.
Anno
------------------------------
Date: Thu, 29 May 2003 10:19:02 +0000 (UTC)
From: Zeljko Vrba <mordor@fly.srk.fer.hr>
Subject: A bug in perl?
Message-Id: <slrnbdbnkm.22d.mordor@fly.srk.fer.hr>
Is there any reason the following wouldn't work:
@{$stud->{'col1', 'col2', 'col3'}} = map { $_ || "" } ($col1, $col2, $col3);
The keys in $stud hash get a funny character after them: less displays
col1 and col2 keys as col1^\ and col2^\ (with ^\ in reverse, that being
ASCII 0x1C = 28). I.e. it appends ASCII 28 to the end of col1 and col2
and sets them as keys in hash. col3 is OK.
whereas
$stud->{col1} = $col1;
$stud->{col2} = $col2;
$stud->{col3} = $col3;
DOES work. I'm using perl 5.6.1.
Thanks for your help!
------------------------------
Date: Thu, 29 May 2003 08:15:50 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: A bug in perl?
Message-Id: <slrnbdc206.33o.tadmc@magna.augustmail.com>
Zeljko Vrba <mordor@fly.srk.fer.hr> wrote:
> Is there any reason the following wouldn't work:
>
> @{$stud->{'col1', 'col2', 'col3'}} = map { $_ || "" } ($col1, $col2, $col3);
Yes.
It appears you were trying to get a hash slice on the LHS, but
that isn't what you have.
> The keys in $stud hash get a funny character after them:
^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^
The value of the $; special variable.
> Thanks for your help!
You could have made it easier for us to help you (which increases
your chances of _getting_ help) by providing a short and complete
program that we can run, as suggested in the Posting Guidelines:
---------------------
#!/usr/bin/perl
use strict;
use warnings;
my $stud;
my($col1, $col2, $col3) = (1,2,3);
@{$stud->{'col1', 'col2', 'col3'}} = map { $_ || "" } ($col1, $col2, $col3);
print "$_ ==> $stud->{$_}\n" for sort keys %$stud;
---------------------
Apply "Use Rule 1" from perlreftut.pod:
@hash{'col1', 'col2', 'col3'} # pretend it is a plain hash
@{}{'col1', 'col2', 'col3'} # replace the hash name with a block...
@{$stud}{'col1', 'col2', 'col3'} # ... that returns a ref to a hash
You then end up with the correct way of slicing your hash:
@{$stud}{'col1', 'col2', 'col3'} = map { $_ || "" } ($col1, $col2, $col3);
or leaving off the extra curlies:
@$stud{'col1', 'col2', 'col3'} = map { $_ || "" } ($col1, $col2, $col3);
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 29 May 2003 13:30:03 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: A bug in perl?
Message-Id: <bb520r$phq$2@mamenchi.zrz.TU-Berlin.DE>
Zeljko Vrba <mordor@fly.srk.fer.hr> wrote in comp.lang.perl.misc:
> Is there any reason the following wouldn't work:
>
> @{$stud->{'col1', 'col2', 'col3'}} = map { $_ || "" } ($col1, $col2, $col3);
^^
The arrow is wrong. $stud->{'col1', 'col2', 'col3'} is a scalar, not the
hash slice you apparently expected. With a hash (instead of a hashref) the
equivalent would be $hash{'col1', 'col2', 'col3'}. This is (obsolete)
syntax to emulate multidimensional hashes.
> The keys in $stud hash get a funny character after them: less displays
> col1 and col2 keys as col1^\ and col2^\ (with ^\ in reverse, that being
> ASCII 0x1C = 28). I.e. it appends ASCII 28 to the end of col1 and col2
> and sets them as keys in hash. col3 is OK.
Look up $; ($SUBSCRIPT_SEPARATOR) in perlvar. The hash slice you want is
written "@{$stud}{'col1', 'col2', 'col3'}"
Anno
------------------------------
Date: 29 May 2003 12:48:26 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Bioperl?
Message-Id: <bb4viq$ns9$1@mamenchi.zrz.TU-Berlin.DE>
Bertt <dragaoon@sappers.no> wrote in comp.lang.perl.misc:
> Uri Guttman wrote:
> >>>>>> "B" == Bertt <dragaoon@sappers.no> writes:
> >
> > >> Abigail,
> > >>
> > >> Yes and no. I've not tried the Bioperl route so far. The Graph
> > module >> on CPAN may/may not be sufficient for my needs - right
> > now I think its >> not....so I decided to see if there is a
> > 'BioPerl' module which I can >> implement.
> >
> >> Don't worry too much about abby, she/he/it used to be a real
> >> helpful person around here before sliding down the abyssful
> >> trollistic ceaspit ;p
> >
> > that last phrase is more like moronzilla style. calling abigail a
> > troll
> > is a good ans ure way to get most regulars to killfile you. now who is
> > the troll?
> >
> >> Really though, I've never seen your previous question answered, and
> >> it has been a while so there absolutely no harm in asking again in
> >> a different way.
> >
> >> Don't let adigail push you way either ;p
> >
> > and your very helpful answer is? not much perl content here. and
> > abigail
> > did discuss graph stuff and modules with the OP. i don't see much
> > pushing away. you have much to learn and i doubt you will learn it
>
> No Abigail did not. She/he/it only offered one line that too had nothing to
> do with Perl. Please do not try to insert something that is blatently not
> there.
Seems like you didn't even look at the other threads about the same
subject. Check your facts.
Anno
------------------------------
Date: 29 May 2003 14:53:39 GMT
From: ctcgag@hotmail.com
Subject: Re: Bioperl?
Message-Id: <20030529105339.205$rM@newsreader.com>
email_entropy123@yahoo.com (entropy123) wrote:
> Hey all,
>
> I'm still trying to figure out how to write a program to detect cycles
> (ring structures) in Perl.
You seem to be going about it in a fairly schizoid way.
> If there is any chance this was done in
> BioPerl I'd like to find out.
I'm pretty sure it isn't in BioPerl, at least not in a chemical sense.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service New Rate! $9.95/Month 50GB
------------------------------
Date: Thu, 29 May 2003 23:33:25 +1200
From: "Tintin" <me@privacy.net>
Subject: Re: copying files to another directory
Message-Id: <bb4r31$5s0ic$1@ID-172104.news.dfncis.de>
<Marck_us_invalid@hotmail.com> wrote in message
news:k0gbdvg3rkfut4q8h80kkt8i0k7vijfjhn@4ax.com...
>
> I need to copy all files from a directory to another one.
>
> I tried this: (copy from defaultfolder to folder)
>
> my @files = `ls $defaultfolder/*.*`;
> my $filename;
>
> foreach $filename(@files)
> {
> `cp $filname $folder/`;
> }
What's the point in writing shell scripts in Perl, write it as a shell
script, or if you do Perl, then
#!/usr/bin/perl
use strict;
use File::Copy;
my $folder="/some/folder";
foreach my $file (<$defaultfolder/*.*>) {
copy($file,"$folder/$file") or warn "Can not copy $file to $folder $!\n";
}
>
> That fails with a strange "cp: missing destination file" !
>
> But if I do the job "by hand", it works fine.
Hand jobs often work fine.
------------------------------
Date: Thu, 29 May 2003 12:23:25 +0200
From: "Craig Manley" <recycle@bin.com>
Subject: Re: hard time with regexp to validate image
Message-Id: <3ed5dfa5$0$194$e4fe514c@dreader3.news.xs4all.nl>
"Matias Woloski" <woloski@sion.com> wrote in message
news:bb43ur$5hga8$1@ID-148083.news.dfncis.de...
> I'm trying to write a regular expression to validate valid images. This
> means that will have to match
>
> Match
> 1) myfile1.gif
> 2) myfile
> 3) myfile.mine.jpg
> 4) my file.jpeg
> etc..
>
> Non-match
> 1) file.exe
> 2) file.vbs
> 3) file.notknownextension
> etc
>
> Those are the basic cases
> So far I did this one
>
> ^[^\.]+(?:\.(?:gif|jpe?g))?$
>
> This will validate every case but leaves out the case 3) where there are
two
> points in the input.
>
> Now that's the problem... How would you change or create a new regexp to
> deal with that?
>
> thanks,
> Matias
>
Hi,
If you just want to match extensions, that's very easy:
my $image = 'bla.jpg';
my $is_it_an_image = $image =~ /.+\.(jpe?g|gif|bmp|ico|png)$/;
my $is_it_unknown = $image =~ /^[^\.]*$/;
There are also modules on CPAN to break file names down into parts if you
just want to extract the extension and match that.
If you want to determine the file type by it's content you need a module
that checks it's "magic" i.e. signature:
You can use Image::Magick (specific for images). It can identify image files
by their 'magic'.
You can also try the other more general (and probably much more light
weight) modules for checking file magic.
-Craig Manley.
------------------------------
Date: Thu, 29 May 2003 10:41:23 -0400
From: Derek Mark Edding <dreq@earthlink.net>
Subject: Help Needed Building Packet
Message-Id: <bb5655$mur$1@slb2.atl.mindspring.net>
Hi Folks,
My Perl has gotten a bit rusty in the last couple of years. I'm looking
for an example that shows how to build a packet (either UDP or IP)
starting with an array of hexadecimal numbers.
I start out with a scalar array, @hexVals, of hexadecimal values for the
packet. I need to convert this to a binary stream of data to give to
send(), called $MSG. This is the character string form of a scalar
variable.
I've been experimenting with map, hex, and pack, but so far the correct
mechanism for performing this conversion is eluding me. Does anyone
know how to get there from here?
Thanks very much!
-dreq
------------------------------
Date: Thu, 29 May 2003 15:57:05 +0100
From: Paul Silver <singleantler-news@hotmail.com>
Subject: How can I get XML::RSS? (ActivePerl)
Message-Id: <2m7cdv40ruuulki9n8lt48538kcrplktl1@4ax.com>
Hi,
I'm trying to get XML::RSS working in ActivePerl, but the readme says
I need to compile it. Unfortunately I have no C compiler.
Does anyone know where I can get a packaged version of XML::RSS that
ppm will be able to cope with? Or any other ideas about getting it
working?
Thanks
Paul
--
Please remove '-news' from address to send e-mail.
http://www.g2blue.co.uk
------------------------------
Date: 29 May 2003 03:48:17 -0700
From: its_all_downhill@yahoo.co.uk (Tom Cutting)
Subject: Image::Grab query
Message-Id: <567270e2.0305290248.6af490dd@posting.google.com>
Hi
As a newbie to Perl, I would like to create a script to grab an image
off a website that is updated every 15 mins from a webcam. I
downloaded the Image::Grab from CPAN and installed it in my perl 5.8.0
dist, but am having problems trying to work out the Date and MD5
options of the module.
at the mo im running a cron job every 15mins.. for the script below.
which works fine. but i would like to make it only download if the
image has been updated. I have looked at the documentation on CPAN and
searched on here but all i can find is the very basic example for
grab_new but im not sure how to use MD5. I have that module installed
to! :o)
#!/usr/bin/perl -w
use strict;
use Image::Grab;
my $pic = new Image::Grab;
sub image_grab {
$pic->url('http://www.mysite.com/mypic.jpg');
$pic->grab;
open(IMAGE, ">$image.jpg");
binmode IMAGE; # for MSDOS derivations.
print IMAGE $pic->image;
close IMAGE;
}
Thanks for any advice
Tom
------------------------------
Date: Thu, 29 May 2003 22:36:26 +0800
From: AcCeSsDeNiEd <dillon@SpamMinuSaccessdenied.darktech.org>
Subject: Piping STDOUT to sendmail via a perl script
Message-Id: <tl5cdvc2r16sem5icfledgl75p39564p5d@4ax.com>
Hi guys,
I wrote a perl script that takes input from sendmail <STDIN> analyzes the input
and then it is suppose to decide whether the recipient should receive it.
I can't get perl to properly send (STDOUT) the data to sendmail.
Or perhaps I can't get sendmail to property receive the output from perl.
My STDOUT in perl goes like this:
open(THEPROG, "| /usr/sbin/sendmail -v dillon@domain.com");
print THEPROG $STDOUT;
close (THEPROG);
But however, if I take $STDOUT and push it to a file and then later push the file sendmail, no
problems, the mail comes in perfectly:
exec ('/usr/sbin/sendmail -v dillon@domain.com < /mailwrite/mailout.wri');
I don;t want to use this method 'cos of file locking and other issues.
Can anyone I help?
To e-mail, remove the obvious
------------------------------
Date: 29 May 2003 08:47:28 -0400
From: Michael Powe <michael@trollope.org>
Subject: Re: Q about assignments for unmatched regex
Message-Id: <u65nt9axr.fsf@trollope.org>
>>>>> "Malcolm" == Malcolm Dew-Jones <yf110@vtn1.victoria.tc.ca> writes:
Malcolm> Michael Powe (michael+gnus@trollope.org) wrote: : hello,
Malcolm> : i am looping through a file matching lines to a regex.
Malcolm> however, some : lines don't return a match. so, i have
Malcolm> something like this: : ...snip...
Malcolm> while (<FH>) {
Malcolm> if ( my ($one,$two,$three,$four,$five,$six) = /$re/ )
Malcolm> { # the re matched, and $one etc are in scope and can be
Malcolm> used } else { # the re did not match, and you can't even
Malcolm> accidently # use the variables due to their scope. }
thanks. this seems so obvious, it rates a 'doh!' i don't know how
many times i've used that same construct ... brain cramp.
thanks again.
mp
--
Michael Powe michael@trollope.org Waterbury CT
ENOSIG: signature file is empty
------------------------------
Date: Thu, 29 May 2003 13:30:17 +0100
From: John Strauss <john.thetenant-s@moving-picture.com>
Subject: Re: regular expression matches but $1 left undefined
Message-Id: <20030529133017.684c1a6a.john.thetenant-s@moving-picture.com>
On 29 May 2003 03:00:59 -0700
justinrobertson@btinternet.com (justin) wrote:
>
> Is it ever possible for a regular expression containing brackets to
> match a string and still leave $1 undefined? Because that's what's
> happening to me.
>
> This is the regular expression:
> GET\s(?:/docs/([A-Fa-f0-9]{32})|/servlet/s\?Name=ShowDoc&(?:id=([A-Fa-f0-9]{32})|pid=([A-Fa-f0-9]{4}-[A-Fa-f0-9]{2}-[A-Fa-f0-9]{2}-[A-Fa-f0-9]{2}-[A-Fa-f0-9]{2})))
>
> And the string is:
> GET /servlet/s?Name=ShowDoc&pid=4559-01-01-00-00&login=1&ref=undefined&ctx=slst&ht=null&seq=1050469368984
> HTTP/1.0
>
> After this match, I thought that $1 should be set to
> "4559-01-01-00-00" but it is in fact always undefined.
>
> This tiny bit of code shows the problem.
>
> $re = 'GET\s(?:/docs/([A-Fa-f0-9]{32})|/servlet/s\?Name=ShowDoc&(?:id=([A-Fa-f0-9]{32})|pid=([A-Fa-f0-9]{4}-[A-Fa-f0-9]{2}-[A-Fa-f0-9]{2}-[A-Fa-f0-9]{2}-[A-Fa-f0-9]{2})))';
> $line = 'GET /servlet/s?Name=ShowDoc&pid=4559-01-01-00-00&login=1&ref=undefined&ctx=slst&ht=null&seq=1050469368984
> HTTP/1.0';
>
> if ($line =~ /$re/) {;
> print $1;
> }
>
> Interestingly though, if you change the last lines to:
>
> print ($line =~ /$re/);
>
> You get "4559-01-01-00-00".
>
> Can anyone help? I've tried $2, $3, etc but no joy. Thanks in advance.
$1 is whatever is captured by the first set of parens to make backreferences:
/docs/([A-Fa-f0-9]{32})
$2 is whatever is captured by the second set of parens to make backreferences:
id=([A-Fa-f0-9]{32})
$3 is whatever is captured by the third set of parens to make backreferences:
pid=([A-Fa-f0-9]{4}-[A-Fa-f0-9]{2}-[A-Fa-f0-9]{2}-[A-Fa-f0-9]{2}-[A-Fa-f0-9]{2})
for your $line, your match is in $3.
you probably need to rework your regexp is you want these to always end up in $1.
this one will put your result in $1, but will match in error if you can have data
containing strings like "/docs/4559-01-01-00-00", or "ShowDoc&id=4559-01-01-00-00"
and don't want them matched:
my $re = 'GET\s(?:/docs/|/servlet/s\?Name=ShowDoc&(?:id=|pid=))([A-Fa-f0-9]{32}|[A-Fa-f0-9]{ 4}-[A-Fa-f0-9]{2}-[A-Fa-f0-9]{2}-[A-Fa-f0-9]{2}-[A-Fa-f0-9]{2})';
i'm sure one of the regexp gurus will step in if i've led you down the garden path.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drop the .thetenant to get me via mail
------------------------------
Date: Thu, 29 May 2003 14:01:52 +0000
From: Garry Short <g4rry_short@zw4llet.com>
Subject: Re: regular expression matches but $1 left undefined
Message-Id: <bb50fn$3ss$1$8302bc10@news.demon.co.uk>
justin wrote:
> $re =
>
'GET\s(?:/docs/([A-Fa-f0-9]{32})|/servlet/s\?Name=ShowDoc&(?:id=([A-Fa-f0-9]{32})|pid=([A-Fa-f0-9]{4}-[A-Fa-f0-9]{2}-[A-Fa-f0-9]{2}-[A-Fa-f0-9]{2}-[A-Fa-f0-9]{2})))';
> $line = 'GET
>
/servlet/s?Name=ShowDoc&pid=4559-01-01-00-00&login=1&ref=undefined&ctx=slst&ht=null&seq=1050469368984
> HTTP/1.0';
>
> if ($line =~ $re) {;
> print $1;
> }
>
Just a clue ... try printing $3 instead ...
Garry
------------------------------
Date: Thu, 29 May 2003 14:08:20 +0000
From: Garry Short <g4rry_short@zw4llet.com>
Subject: Re: regular expression matches but $1 left undefined
Message-Id: <bb50rp$3ss$2$8302bc10@news.demon.co.uk>
John Strauss wrote:
> On 29 May 2003 03:00:59 -0700
> justinrobertson@btinternet.com (justin) wrote:
>>
>> Is it ever possible for a regular expression containing brackets to
>> match a string and still leave $1 undefined? Because that's what's
>> happening to me.
>>
>> This is the regular expression:
>>
GET\s(?:/docs/([A-Fa-f0-9]{32})|/servlet/s\?Name=ShowDoc&(?:id=([A-Fa-f0-9]{32})|pid=([A-Fa-f0-9]{4}-[A-Fa-f0-9]{2}-[A-Fa-f0-9]{2}-[A-Fa-f0-9]{2}-[A-Fa-f0-9]{2})))
>>
>> And the string is:
>> GET
>>
/servlet/s?Name=ShowDoc&pid=4559-01-01-00-00&login=1&ref=undefined&ctx=slst&ht=null&seq=1050469368984
>> HTTP/1.0
>>
>> After this match, I thought that $1 should be set to
>> "4559-01-01-00-00" but it is in fact always undefined.
>>
>> This tiny bit of code shows the problem.
>>
>> $re =
>>
'GET\s(?:/docs/([A-Fa-f0-9]{32})|/servlet/s\?Name=ShowDoc&(?:id=([A-Fa-f0-9]{32})|pid=([A-Fa-f0-9]{4}-[A-Fa-f0-9]{2}-[A-Fa-f0-9]{2}-[A-Fa-f0-9]{2}-[A-Fa-f0-9]{2})))';
>> $line = 'GET
>>
/servlet/s?Name=ShowDoc&pid=4559-01-01-00-00&login=1&ref=undefined&ctx=slst&ht=null&seq=1050469368984
>> HTTP/1.0';
>>
>> if ($line =~ /$re/) {;
>> print $1;
>> }
>>
>> Interestingly though, if you change the last lines to:
>>
>> print ($line =~ /$re/);
>>
>> You get "4559-01-01-00-00".
>>
>> Can anyone help? I've tried $2, $3, etc but no joy. Thanks in advance.
>
> $1 is whatever is captured by the first set of parens to make
> backreferences: /docs/([A-Fa-f0-9]{32})
>
> $2 is whatever is captured by the second set of parens to make
> backreferences: id=([A-Fa-f0-9]{32})
>
> $3 is whatever is captured by the third set of parens to make
> backreferences:
>
pid=([A-Fa-f0-9]{4}-[A-Fa-f0-9]{2}-[A-Fa-f0-9]{2}-[A-Fa-f0-9]{2}-[A-Fa-f0-9]{2})
>
> for your $line, your match is in $3.
>
> you probably need to rework your regexp is you want these to always end up
> in $1.
>
> this one will put your result in $1, but will match in error if you can
> have data containing strings like "/docs/4559-01-01-00-00", or
> "ShowDoc&id=4559-01-01-00-00" and don't want them matched:
>
> my $re =
>
'GET\s(?:/docs/|/servlet/s\?Name=ShowDoc&(?:id=|pid=))([A-Fa-f0-9]{32}|[A-Fa-f0-9]{
> 4}-[A-Fa-f0-9]{2}-[A-Fa-f0-9]{2}-[A-Fa-f0-9]{2}-[A-Fa-f0-9]{2})';
>
> i'm sure one of the regexp gurus will step in if i've led you down the
> garden path.
>
>
>
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> drop the .thetenant to get me via mail
Alternatively, stick with the regex you've got. Then remove the "print $1"
line and replace it with something like:
print "1. $1\n" if $1;
print "2. $2\n" if $2;
print "3. $3\n" if $3;
The print command will only happen if $x is defined, where x is 1,2 or 3.
You'll only ever get one match, since they're all alternatives within the
regex.
Regards,
Garry
------------------------------
Date: Thu, 29 May 2003 08:00:56 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: regular expression matches but $1 left undefined
Message-Id: <slrnbdc148.33o.tadmc@magna.augustmail.com>
justin <justinrobertson@btinternet.com> wrote:
> Is it ever possible for a regular expression containing brackets to
> match a string and still leave $1 undefined?
Yes, when the part of the regex containing the 1st parens is
not the part of the regex that matched.
> This is the regular expression:
[ snip match (in scalar context) of the form: /()|()|()/ ]
> And the string is:
[ snip a string that can be matched by the 3rd alternation.
> After this match, I thought that $1 should be set
Why would you think that?
$1 will be set when the part of the regex containing the 1st set
of parens matches.
Since you are matching the 3rd alternation, the data is in $3.
> Interestingly though,
It is even more interesting in that it triggers warnings that
are a clue as to what is happening.
You do enable warnings when developing Perl code, don't you?
> if you change the last lines to:
>
> print ($line =~ /$re/);
>
> You get "4559-01-01-00-00".
Actually you get: undef, undef, "4559-01-01-00-00"
(ie. $1,$2,$3) from the m// in list context.
> Can anyone help?
Since you have only one capturing parens per alternation, you
can just filter out the undef'd ones, leaving only the one
that matched:
if (my($matched) = grep defined, $line =~ /$re/) {
print $matched, "\n";
}
But then you won't know which part was the one that matched...
> I've tried $2, $3, etc but no joy.
Well then I don't know what is happening.
It works for me using $3.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 29 May 2003 08:48:25 -0500
From: "Kevin Vaughn" <kevin.vaughn@ttu.edu>
Subject: Re: Semi-Newbie Steps Into Module Hell
Message-Id: <vdc3tl2kuca765@corp.supernews.com>
Thanks for the help guys. I'm pretty sure my installation is botched. Now
I can't get it to work at all. I get errors either way I run it (with .1403
or .1501). I am either going to reinstall or upgrade to 5.8.
I found no other instances of ole.pm outside of lib and site/lib.
Assuming I reinstall Perl and I don't upgrade to 5.8, what would be the
proper way to upgrade ole.pm? I know I should RTFM - can you refer me to
the proper one?
What's the difference between lib and site/lib anyway?
-Kevin
------------------------------
Date: Thu, 29 May 2003 12:14:25 +0200
From: "Craig Manley" <recycle@bin.com>
Subject: Re: Tempopary files on Win32
Message-Id: <3ed5dd8a$0$182$e4fe514c@dreader3.news.xs4all.nl>
"Roman Khutkyy" <beromko@yahoo.com> wrote in message
news:bb4gpg$1lte$1@news.uar.net...
> 1. During uploading files from user mashine (thruough browser form) to
> server Perl creates temporary files in C:\Temp directory (CGItemp****) and
> does not delete them after aploading finished. How to make Perl clean
after
> itself.
> 2. I'm trying to read those files like this:
> $filename=$query->param('filename');
> open (INFILE,"<$filename");
> binmode(INFILE);
> But this method works only if load files from IE browser (from this
browser
> returned parameter of filefield includes full file name including path).
Any
> other browser (Opera, Mozilla) returns only filename without path, and
> result of reading in this case is empty file. Is there any method to read
> from TEMP file or to make Perl to read downloaded files as STDIN (it must
be
> so but it doesn't)
>
>
Hi,
Never make assumptions of the actual file name on your system given the file
name the browser sent. The CGI class has 2 safer options: the real file name
on your system or the open file handle of the uploaded file.
If for example the parameter name of the uploaded file is "file" then you
can do this:
my $infilehandle = $r->upload('file');
# This block is only necessary if you need to check file types
my $infileinfo = $r->uploadInfo($infilehandle);
unless(defined($infileinfo->{'Content-Type'}) &&
($infileinfo->{'Content-Type'} eq 'audio/mpeg')) {
die "Hey I expect MP3 files only!\n";
}
# Read file into memory and save as a unique named file.
binmode($infilehandle); # keep code portable accross all OS'.
my $id = &just_some_unique_id_generator();
my $outfilename = "/My Stupid OS/My Documents/My First Sony/My Music
Files/$id.mp3";
my $outfilehandle;
if (open($outfilehandle,">$outfilename")) {
binmode($outfilehandle); # keep code portable accross all OS'.
my $bytesread;
my $buffer;
while ($bytesread=read($infilehandle,$buffer,1024)) {
print $outfilehandle $buffer;
}
close($outfilehandle);
close($infilehandle);
}
else {
die "Failed to create file \"$outfilename\".\n";
}
-Craig Manley
------------------------------
Date: Thu, 29 May 2003 11:32:36 +0100
From: SeeMySig <spam.me.senseless@sitting.duck>
Subject: Re: uninitialized value in eval block?
Message-Id: <YFDrjQCEHe1+EwrJ@nildram.co.uk>
In message <slrnbdagqp.1vn.tadmc@magna.augustmail.com>, Tad McClellan
<tadmc@augustmail.com> writes
>SeeMySig <spam.me.senseless@sitting.duck> wrote:
>> In message <slrnbdaaod.1qv.tadmc@magna.augustmail.com>, Tad McClellan
>><tadmc@augustmail.com> writes
>>>SeeMySig <spam.me.senseless@sitting.duck> wrote:
>
>>>><!-- warning: Use of uninitialized value in concatenation (.) or string
>>>> at (eval 18) line 32. -->
>>>>
[ Stuff that's not relevant anymore was here... ]
>How is it that you are doing so many evals anyway?
>
>Are they all of the "eval BLOCK" form rather than the "eval EXPR" form?
See below.
>
[ And here ]
>> But I have to ask why do most other warnings localise to an actual line
>> in the script, and so are pretty easy to correct, but this one does a
>> cryptic 'you-may-find-it-if-you-look-hard-enough'?
>
>
>Because you put it in an eval.
>
>You are running perl inside of perl, that makes it "hard(er)".
In fact my cgi script is written as a series of if, elsif, elsif, etc
statements, each one pointing to a different sub-routine to handle SQL
processing and subsequent HTML generation (using CGI.pm of course). I
find this easier as I can follow the logic that way - the HTML response
depends on the params passed from the web-form, like this:
eval {
if ($in{'param_1'}) { &sub_routine_1 } # eg param_1 is 'search'
elsif ($in{'param_2'}) { &sub_routine_2 } # eg param_2 is 'new record'
etc.
};
There are about 25 (so far) of these elsif statements inside the eval,
and that is all there is - the final 'else' is an 'input not recognised'
message. All of the logic is done inside the sub-routines. It was
apparently the 18th line of the eval that upset the parser.
It seemed a good idea to put the if/elsif statements inside an eval to
catch any errors, but I am happy to stand corrected on this arrangement.
I'm not sure if this makes it a perl-within-perl arrangement?
Given the architecture of my script, I still do not see why most other
warnings localise to a specific line in a specific sub-routine, but this
one points to an elsif statement inside the eval (which like all others
has a sub-routine associated with it).
--
RA Jones
ra(dot)jones(at)dpw(dot)clara(dot)net
------------------------------
Date: Thu, 29 May 2003 12:03:21 +0100
From: SeeMySig <spam.me.senseless@sitting.duck>
Subject: Re: uninitialized value in eval block?
Message-Id: <RUc5XnE5je1+EwrW@nildram.co.uk>
In message <bb4a2v$64f$1@nets3.rz.RWTH-Aachen.DE>, Tassilo v. Parseval
<tassilo.parseval@rwth-aachen.de> writes
>Also sprach Tad McClellan:
>
>> SeeMySig <spam.me.senseless@sitting.duck> wrote:
>
>>> The question is, where do I look for the source of the violation in eval
>>> 18 line 32?
>>
>>
>> step 1) determine what the 18th eval() is that your program is evaluating.
>>
>> step 2) count in that eval to the 32nd line.
>>
>> step 3) look for undef values near there
>
>For larger pieces that are executed within an eval(), it's sometimes not
>a bad idea to add #line comments:
>
> eval <<EOEVAL;
> ...
> #line 100 (oops)
> die;
> EOEVAL
>
>Results in the much more meaningful
>
> Died at (oops) line 100.
Que? I can see that would work if I knew it was going to choke at line
100, but then if I knew that...
How does it help me otherwise within a large eval block?
--
RA Jones
ra(dot)jones(at)dpw(dot)clara(dot)net
------------------------------
Date: 29 May 2003 11:37:04 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: uninitialized value in eval block?
Message-Id: <bb4rd0$l16$1@nets3.rz.RWTH-Aachen.DE>
Also sprach SeeMySig:
> In message <bb4a2v$64f$1@nets3.rz.RWTH-Aachen.DE>, Tassilo v. Parseval
><tassilo.parseval@rwth-aachen.de> writes
>>For larger pieces that are executed within an eval(), it's sometimes not
>>a bad idea to add #line comments:
>>
>> eval <<EOEVAL;
>> ...
>> #line 100 (oops)
>> die;
>> EOEVAL
>>
>>Results in the much more meaningful
>>
>> Died at (oops) line 100.
> Que? I can see that would work if I knew it was going to choke at line
> 100, but then if I knew that...
>
> How does it help me otherwise within a large eval block?
Take this example:
my $method1 = <<EOMETH1;
sub {
#line 1 (method1)
print "hello";
die;
}
EOMETH1
$method2 = <<EOMETH2;
sub {
#line 1 (method2)
print "hello";
die;
}
EOMETH2
*meth1 = eval $method1;
*meth2 = eval $method2;
meth2();
__END__
Died at (method2) line 2.
Consider CGI.pm that has a lot of methods defined as strings that later
get evaluated (like the above). It is not always spontaneously obvious
which one failed. But if each method at least has a label, you instantly
know which piece of string croaked. Counting a couple of lines in such a
bunch of code is then left as a trivial excercise. It is certainly much
clearer than the usual
Died at (eval 2) line 4.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Thu, 29 May 2003 16:03:52 +0200
From: Winfried Koenig <w.koenig@acm.org>
Subject: Re: uninitialized value in eval block?
Message-Id: <3ED61348.3000908@acm.org>
Tassilo v. Parseval wrote:
> Also sprach SeeMySig:
>
>
>>In message <bb4a2v$64f$1@nets3.rz.RWTH-Aachen.DE>, Tassilo v. Parseval
>><tassilo.parseval@rwth-aachen.de> writes
>
>
>>>For larger pieces that are executed within an eval(), it's sometimes not
>>>a bad idea to add #line comments:
>>>
>>> eval <<EOEVAL;
>>> ...
>>> #line 100 (oops)
>>> die;
>>> EOEVAL
>>>
>>>Results in the much more meaningful
>>>
>>> Died at (oops) line 100.
>>
>>Que? I can see that would work if I knew it was going to choke at line
>>100, but then if I knew that...
>>
>>How does it help me otherwise within a large eval block?
>
>
> Take this example:
>
> my $method1 = <<EOMETH1;
> sub {
> #line 1 (method1)
> print "hello";
> die;
> }
> EOMETH1
>
> $method2 = <<EOMETH2;
> sub {
> #line 1 (method2)
> print "hello";
> die;
> }
> EOMETH2
>
> *meth1 = eval $method1;
> *meth2 = eval $method2;
>
> meth2();
> __END__
> Died at (method2) line 2.
>
> Consider CGI.pm that has a lot of methods defined as strings that later
> get evaluated (like the above). It is not always spontaneously obvious
> which one failed. But if each method at least has a label, you instantly
> know which piece of string croaked. Counting a couple of lines in such a
> bunch of code is then left as a trivial excercise. It is certainly much
> clearer than the usual
>
> Died at (eval 2) line 4.
Hmm, for Perl Versions 5.003 up to 5.8.0 the line directive must
start at beginning of a line. For Versions 5.003 to 5.6.0 the
directive must not be in the first evaluated line. So the example
should read:
my $method2 = <<EOMETH2;
sub {
# line 2 (method2)
print "hello\n";
die;
}
EOMETH2
Winfried
__
Winfried Koenig +49 69 868707 w.koenig@acm.org
Perl - Beratung und Programmierung in Unixumgebung
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.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.
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 V10 Issue 5056
***************************************