[16449] in Perl-Users-Digest
Perl-Users Digest, Issue: 3861 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jul 31 18:10:48 2000
Date: Mon, 31 Jul 2000 15:10:33 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <965081432-v9-i3861@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 31 Jul 2000 Volume: 9 Number: 3861
Today's topics:
Re: parallelport programming in PERL <gellyfish@gellyfish.com>
password protected web pages <diane@dmswebsupport.com>
Re: Perl jobs? <lemming@informix.com>
Perl System command <jdodd@mbcnet.com>
Re: Perl System command <newsposter@cthulhu.demon.nl>
Re: Perl System command <jeffp@crusoe.net>
Re: Perl System command <tina@streetmail.com>
Please unconfuse me.... if (<>)... rocoto@my-deja.com
Re: Please unconfuse me.... if (<>)... <tina@streetmail.com>
Re: Please unconfuse me.... if (<>)... aqutiv@my-deja.com
Re: POSIX::mktime <tim@ipac.caltech.edu>
printf %e exponent digits <jonathan.kuhn@gsfc.nasa.gov>
Re: printf %e exponent digits (Colin Keith)
Re: printf %e exponent digits <jonathan.kuhn@gsfc.nasa.gov>
Re: printf %e exponent digits (Colin Keith)
Re: printf %e exponent digits <tim@ipac.caltech.edu>
Re: printf %e exponent digits <jonathan.kuhn@gsfc.nasa.gov>
question about a Regular Expression <phil.taylor@bigfoot.com>
Re: question about a Regular Expression <stephen.kloder@gtri.gatech.edu>
Re: question about a Regular Expression (Greg Bacon)
Re: question about a Regular Expression <tina@streetmail.com>
Re: Question on sorting an array (Mark-Jason Dominus)
Re: Quotes in regex? (Colin Keith)
Re: regular expression (Andrew J. Perrin)
Re: regular expression (Greg Bacon)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 31 Jul 2000 21:37:07 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: parallelport programming in PERL
Message-Id: <8m4o1j$am2$1@orpheus.gellyfish.com>
On Thu, 27 Jul 2000 07:02:18 GMT schanbacher@my-deja.com wrote:
> Hi,
>
> does anyone know how it is possible to programm the
> parallelport in PERL on a Linux PC ?
>
Presumably by doing the appropriate ioctls on '/dev/par0' or whatever the
appropriate device is. You probably want to ask in some Linux group
as to what exactly those ioctls might be .
/J\
--
yapc::Europe in assocation with the Institute Of Contemporary Arts
<http://www.yapc.org/Europe/> <http://www.ica.org.uk>
------------------------------
Date: Mon, 31 Jul 2000 15:50:14 -0400
From: "Diane" <diane@dmswebsupport.com>
Subject: password protected web pages
Message-Id: <sobm0f8c9ft47@corp.supernews.com>
Any suggestions for some good references for perl scripts which restrict
access to certain parts of a website? What I need to do is find/write a perl
script that will allow the user to choose a username and password as part of
a registration form, and get immediate access to those pages. The user
should also have the ability to have the password send I've used the
authenticate program from Matt Wright & Craig Patchett's "CGI/Perl
Cookbook", but was wondering what else is available. Any perl modules that
would be helpful in writing my own script? I looked through the perl module
list and didn't see anything but maybe I missed something.
Thanks!
Diane
------------------------------
Date: Mon, 31 Jul 2000 12:00:41 -0700
From: Mark Morgan <lemming@informix.com>
Subject: Re: Perl jobs?
Message-Id: <3985CCD9.91FEA1A@informix.com>
Ben Addis wrote:
>
> There are jobs for most programming languages. It just depends on what you
> want to do.
>
> If your that worried, why not just learn both?
>
> Ben
> "peter" <peterp100@hotmail.com> wrote in message
> news:kre4os899d2g278fl1i22bfeoj59ipmg0h@4ax.com...
> > I'm teaching myself perl and I'm taking a Java class this fall. But,
> > I'm thinking about dropping the Java class and concentrating on Perl.
> > Are there any jobs out there for perl programmers? When I look in the
> > paper everything says "Java and C ++" ???
I agree with Ben. The more languages you know, the better off you'll
be. And depending on the class, you might learn some tricks from the
java class that will apply to perl. Or any other language for that
matter.
--
Mark Morgan
lemming@informix.com
503-525-7528
------------------------------
Date: Mon, 31 Jul 2000 14:43:33 -0400
From: "John Dodd" <jdodd@mbcnet.com>
Subject: Perl System command
Message-Id: <3985c84f$0$16682@wodc7nh0.news.uu.net>
Using system(date); gives me the default date of Dec 31, 1969. However when
I type date at the prompt the correct date of July 31, 2000 is giving. Does
anyone know why this happens. I'm new to perl, but I would assume it is the
same in c.
John Dodd
------------------------------
Date: 31 Jul 2000 19:10:27 GMT
From: Erik van Roode <newsposter@cthulhu.demon.nl>
Subject: Re: Perl System command
Message-Id: <8m4iv3$aaq$3@internal-news.uu.net>
In comp.lang.perl.misc John Dodd <jdodd@mbcnet.com> wrote:
> Using system(date); gives me the default date of Dec 31, 1969. However when
> I type date at the prompt the correct date of July 31, 2000 is giving. Does
> anyone know why this happens. I'm new to perl, but I would assume it is the
> same in c.
You're probably doing something wrong, but without seeing the code
it is impossible to see what. But you probably want to look at the
documentation for 'localtime'. If you insist on using the external
date, you probably should read the documentation for system to see
whether you really want to use system.
Erik
------------------------------
Date: Mon, 31 Jul 2000 15:30:44 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: Perl System command
Message-Id: <Pine.GSO.4.21.0007311529410.4304-100000@crusoe.crusoe.net>
[posted & mailed]
>Using system(date); gives me the default date of Dec 31, 1969. However when
>I type date at the prompt the correct date of July 31, 2000 is giving. Does
>anyone know why this happens. I'm new to perl, but I would assume it is the
>same in c.
How are you using the system() function?
$date = system 'date';
If so, you're doing something VERY wrong. system() returns the system
return value (0 for success, non-0 otherwise).
Why not just say:
$date = localtime;
--
Jeff "japhy" Pinyan japhy@pobox.com http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc. http://www.perlarchive.com/
CPAN - #1 Perl Resource (my id: PINYAN) http://search.cpan.org/
------------------------------
Date: 31 Jul 2000 20:27:13 GMT
From: Tina Mueller <tina@streetmail.com>
Subject: Re: Perl System command
Message-Id: <8m4nf1$5mcr3$1@ID-24002.news.cis.dfn.de>
hi,
In comp.lang.perl.misc John Dodd <jdodd@mbcnet.com> wrote:
> Using system(date); gives me the default date of Dec 31, 1969.
use
system('date');
(but this won't solve the problem itself)
> However when
> I type date at the prompt the correct date of July 31, 2000 is giving. Does
> anyone know why this happens. I'm new to perl, but I would assume it is the
> same in c.
more info please. which is your default shell?
you may want to use the perl function localtime
perldoc -f localtime
tina
--
http://tinita.de \ enter__| |__the___ _ _ ___
tina's moviedatabase \ / _` / _ \/ _ \ '_(_-< of
search & add comments \ \ _,_\ __/\ __/_| /__/ perception
please no answers via email unless followup is set to poster.
------------------------------
Date: Mon, 31 Jul 2000 20:20:25 GMT
From: rocoto@my-deja.com
Subject: Please unconfuse me.... if (<>)...
Message-Id: <8m4n24$ecv$1@nnrp1.deja.com>
Ok.... I give up.... I just ran into a perl behavior issue I am unable
to resolve - so for the time being, I've just programmed around it....
However, it irks me to not be able to get to the bottom of something...
There *has* to be some logical explanation somewhere for this....
Given these constructs:
while (<>) { ... }
for (1;<>;1) { ... }
Why doesn't this work:
if (<>) { ... }
At least it [mis]behaves consistently from VMS to Linux...
I'm sooooooo confused.....
Thanks in advance....
$ perl -we 'if (<>) { print $_; }'
asf
Use of uninitialized value at -e line 1, <> chunk 1.
$ perl -v
This is perl, version 5.005_03 built for i386-linux
$
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 31 Jul 2000 20:52:19 GMT
From: Tina Mueller <tina@streetmail.com>
Subject: Re: Please unconfuse me.... if (<>)...
Message-Id: <8m4ou2$5mcr3$3@ID-24002.news.cis.dfn.de>
hi,
rocoto@my-deja.com wrote:
> Ok.... I give up.... I just ran into a perl behavior issue I am unable
> to resolve - so for the time being, I've just programmed around it....
> However, it irks me to not be able to get to the bottom of something...
> There *has* to be some logical explanation somewhere for this....
> Given these constructs:
> while (<>) { ... }
> for (1;<>;1) { ... }
while (<>) {}
is like doing
while ($_ = <>) {}
(the same with for)
> Why doesn't this work:
> if (<>) { ... }
here <> is just evaluated, but assigned to if, so
if there's something in the first line
(of course, the "\n"),
the if is true. but $_ is still empty.
> At least it [mis]behaves consistently from VMS to Linux...
> $ perl -we 'if (<>) { print $_; }'
> asf
> Use of uninitialized value at -e line 1, <> chunk 1.
better do:
perl -we 'if (defined($_ = <>)) {print}'
HTH,
tina
--
http://tinita.de \ enter__| |__the___ _ _ ___
tina's moviedatabase \ / _` / _ \/ _ \ '_(_-< of
search & add comments \ \ _,_\ __/\ __/_| /__/ perception
please no answers via email unless followup is set to poster.
------------------------------
Date: Mon, 31 Jul 2000 21:03:54 GMT
From: aqutiv@my-deja.com
Subject: Re: Please unconfuse me.... if (<>)...
Message-Id: <8m4pjn$ghe$1@nnrp1.deja.com>
In article <8m4n24$ecv$1@nnrp1.deja.com>,
rocoto@my-deja.com wrote:
> Ok.... I give up.... I just ran into a perl behavior issue I am unable
> to resolve - so for the time being, I've just programmed around it....
> However, it irks me to not be able to get to the bottom of
something...
> There *has* to be some logical explanation somewhere for this....
>
> Given these constructs:
> while (<>) { ... }
> for (1;<>;1) { ... }
>
> Why doesn't this work:
> if (<>) { ... }
>
> At least it [mis]behaves consistently from VMS to Linux...
>
> I'm sooooooo confused.....
Because $_ is only defined for each eleement of a loop.
perl -e "print if <>"
doesn't work. (remind you, $_ is a default, no need to specify it)
perl -e "print $var if $var = <>"
This works... If that's what you meant.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 31 Jul 2000 14:33:09 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: POSIX::mktime
Message-Id: <3985F095.BA5730CB@ipac.caltech.edu>
Chest Rockwell wrote:
>
> Hi there,
>
> I am trying to get the Unix time (nr seconds since 1970) for every day
> at 00:00 since 2000 (for testing purposes). I am using the mktime
> function from POSIX in a for loop. But I can't seem to get the $yday
> (day of the year) argument working. My code looks someting like this:
>
> for ($i=0;$i<366;$i++){
> $mytime = mktime(?,?,?,?,?,? etc)
> ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
> localtime($mytime)
'man mktime' sez:
"The function ignores the specified contents of the structure members
tm_wday and tm_yday and recomputes them from the other information
in the broken-down time structure."
When I wanted to do something similar, I looked into the modules in the
'Time::*' hierarchy on CPAN.
--
-- Tim Conrow tim@ipac.caltech.edu 626-395-8435
------------------------------
Date: Mon, 31 Jul 2000 16:02:36 -0400
From: Jonathan Kuhn <jonathan.kuhn@gsfc.nasa.gov>
Subject: printf %e exponent digits
Message-Id: <3985DB5C.D96593BD@gsfc.nasa.gov>
Hello Again,
It was not clear from my first note that I am having problems with the
number of digits in the EXPONENT when I use the %e descriptor. Under
windows NT the output has 3 digits in the exponent, but I need to have
only 2 digits.
Jonathan
--
Dr. Jonathan Kuhn
Mechanical Systems Analysis and Simulation Branch
NASA Goddard Space Flight Center Code 542
Greenbelt, MD 20771
Office: Bldg 5 Room C310A
Phone: (301) 286-4278
FAX: (301) 286-0204
Email: jonathan.kuhn@gsfc.nasa.gov
URL: http://analyst.gsfc.nasa.gov/jkuhn
------------------------------
Date: Mon, 31 Jul 2000 19:28:45 GMT
From: ckeith@clara.net (Colin Keith)
Subject: Re: printf %e exponent digits
Message-Id: <Nrkh5.56$DT4.2119416@nnrp2.clara.net>
In article <39859F7C.96A1F360@gsfc.nasa.gov>, Jonathan Kuhn
<jonathan.kuhn@gsfc.nasa.gov> wrote:
>Hello,
>
>How do you set the number of digits for the %e descriptor in printf? I
>must have 2 digits, but activeperl under windows nt is giving 3. Perl on
>an SGI with IRIX is giving 2.
which digits, before or after the . ?
$_ = 34.3343;
printf("%2.3e\n", $_);
3.433e+01
>Sorry if the answer to this is out there somewhere, but I have spent
>over an hour searching and haven't found anything.
man perlfunc => sprintf
At least, assuming I gave the answer you wanted (which I don't think I did
because I'm not sure which digits you're refering to.) I'd have thought "%f"
would be a better fit for 'set the number of digits'. Still I ain't a
scientist, you is ... urm, well actually I am, but I have letters after my
name, not in front, so you're cleverer:)
---
Colin Keith
Systems Administrator
Network Operations Team
ClaraNET (UK) Ltd. NOC
------------------------------
Date: Mon, 31 Jul 2000 16:06:11 -0400
From: Jonathan Kuhn <jonathan.kuhn@gsfc.nasa.gov>
Subject: Re: printf %e exponent digits
Message-Id: <3985DC33.8B6EBDAE@gsfc.nasa.gov>
Colin,
Thanks for your response. In your example I get the following:
$_ = 34.3343;
printf("%2.3e\n", $_);
3.433e+001
In other word the exponent is '001' instead of '01'.
Any ideas?
Jonathan
Colin Keith wrote:
>
> In article <39859F7C.96A1F360@gsfc.nasa.gov>, Jonathan Kuhn
> <jonathan.kuhn@gsfc.nasa.gov> wrote:
> >Hello,
> >
> >How do you set the number of digits for the %e descriptor in printf? I
> >must have 2 digits, but activeperl under windows nt is giving 3. Perl on
> >an SGI with IRIX is giving 2.
>
> which digits, before or after the . ?
>
> $_ = 34.3343;
> printf("%2.3e\n", $_);
> 3.433e+01
>
> >Sorry if the answer to this is out there somewhere, but I have spent
> >over an hour searching and haven't found anything.
>
> man perlfunc => sprintf
>
> At least, assuming I gave the answer you wanted (which I don't think I did
> because I'm not sure which digits you're refering to.) I'd have thought "%f"
> would be a better fit for 'set the number of digits'. Still I ain't a
> scientist, you is ... urm, well actually I am, but I have letters after my
> name, not in front, so you're cleverer:)
>
> ---
> Colin Keith
> Systems Administrator
> Network Operations Team
> ClaraNET (UK) Ltd. NOC
--
Dr. Jonathan Kuhn
Mechanical Systems Analysis and Simulation Branch
NASA Goddard Space Flight Center Code 542
Greenbelt, MD 20771
Office: Bldg 5 Room C310A
Phone: (301) 286-4278
FAX: (301) 286-0204
Email: jonathan.kuhn@gsfc.nasa.gov
URL: http://analyst.gsfc.nasa.gov/jkuhn
------------------------------
Date: Mon, 31 Jul 2000 20:50:23 GMT
From: ckeith@clara.net (Colin Keith)
Subject: Re: printf %e exponent digits
Message-Id: <jElh5.61$DT4.2130032@nnrp2.clara.net>
In article <3985DC33.8B6EBDAE@gsfc.nasa.gov>, Jonathan Kuhn <jonathan.kuhn@gsfc.nasa.gov> wrote:
>Colin,
>
>Thanks for your response. In your example I get the following:
>
>$_ = 34.3343;
>printf("%2.3e\n", $_);
>3.433e+001
>
>In other word the exponent is '001' instead of '01'.
>Any ideas?
Ohhh. No :(
Urm. run it through s/\+0// ?
I would wander (aimlessly) towards POSIX / locales given your posting
address (doesn't the US gov dictate POSIX compliancy for all machines it
runs?) but a reference in the man page for sprintf(3) (and a thread in
comp.lang.c) suggest it might be a C feature "The exponent always contains
*at least* two digits; if the value is zero, the exponent is 00."
Sorry, I can't find anything else out about this though. The regexp is the
best I can suggest.
Col.
---
Colin Keith
Systems Administrator
Network Operations Team
ClaraNET (UK) Ltd. NOC
------------------------------
Date: Mon, 31 Jul 2000 13:58:12 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: printf %e exponent digits
Message-Id: <3985E864.32D30A31@ipac.caltech.edu>
Jonathan Kuhn wrote:
> How do you set the number of digits for the %e descriptor in printf? I
> must have 2 digits, but activeperl under windows nt is giving 3. Perl on
> an SGI with IRIX is giving 2.
Perl on *NIX uses the underlying libc *printf routines (I think), which
should work as documented. I.e.
perl -we 'printf("%10.2e\n",123.456e10)'
1.23e+12
If activeperl under NT doesn't produce this o/p for this example, let
the good folks at ActiveState know. If that's not what you meant,
perhaps an example with output which fails for you would help.
--
-- Tim Conrow tim@ipac.caltech.edu 626-395-8435
------------------------------
Date: Mon, 31 Jul 2000 17:22:46 -0400
From: Jonathan Kuhn <jonathan.kuhn@gsfc.nasa.gov>
Subject: Re: printf %e exponent digits
Message-Id: <3985EE26.AF8B27B9@gsfc.nasa.gov>
Hello,
Here is what I get:
perl -we 'printf("%10.2e\n",123.456e10)'
1.23e+012
I ended up running the strings through s/([+-])\d(\d\d)/$1$2/g
I will e-mail a description to activestate.
Colin and Tim, thanks for your help.
Sincerely,
Jonathan
Tim Conrow wrote:
>
> Jonathan Kuhn wrote:
> > How do you set the number of digits for the %e descriptor in printf? I
> > must have 2 digits, but activeperl under windows nt is giving 3. Perl on
> > an SGI with IRIX is giving 2.
>
> Perl on *NIX uses the underlying libc *printf routines (I think), which
> should work as documented. I.e.
>
> perl -we 'printf("%10.2e\n",123.456e10)'
> 1.23e+12
>
> If activeperl under NT doesn't produce this o/p for this example, let
> the good folks at ActiveState know. If that's not what you meant,
> perhaps an example with output which fails for you would help.
>
> --
>
> -- Tim Conrow tim@ipac.caltech.edu 626-395-8435
--
Dr. Jonathan Kuhn
Mechanical Systems Analysis and Simulation Branch
NASA Goddard Space Flight Center Code 542
Greenbelt, MD 20771
Office: Bldg 5 Room C310A
Phone: (301) 286-4278
FAX: (301) 286-0204
Email: jonathan.kuhn@gsfc.nasa.gov
URL: http://analyst.gsfc.nasa.gov/jkuhn
------------------------------
Date: Mon, 31 Jul 2000 21:37:46 +0100
From: "Philip Taylor" <phil.taylor@bigfoot.com>
Subject: question about a Regular Expression
Message-Id: <8m4o2e$krs$1@news6.svr.pol.co.uk>
I have constructed the following regular expression to validate scores:-
/^\s*[0-9]{1,2}\s*\-\s*[0-9]{1,2}\s*$/
it's purpose is to validate scores eg "13-2", but I also want to allow for
spaces being entered within the score eg " 12 - 2".
It seems a bit long winded and I would be grateful for suggestions on how
it's form/performance may be improved.
cheers
Phil
------------------------------
Date: Mon, 31 Jul 2000 16:54:20 -0400
From: Stephen Kloder <stephen.kloder@gtri.gatech.edu>
Subject: Re: question about a Regular Expression
Message-Id: <3985E77B.B52286C8@gtri.gatech.edu>
Philip Taylor wrote:
> I have constructed the following regular expression to validate scores:-
>
> /^\s*[0-9]{1,2}\s*\-\s*[0-9]{1,2}\s*$/
>
> it's purpose is to validate scores eg "13-2", but I also want to allow for
> spaces being entered within the score eg " 12 - 2".
>
> It seems a bit long winded and I would be grateful for suggestions on how
> it's form/performance may be improved.
>
> cheers
>
I would recommend stripping out the spaces first:
s/\s+//g;
Then matching with
/^\d{1,2}\-\d{1,2}$/
Recall that \d is the same as [0-9]
------------------------------
Date: Mon, 31 Jul 2000 21:01:26 GMT
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: question about a Regular Expression
Message-Id: <sobq96ug9ft7@corp.supernews.com>
In article <8m4o2e$krs$1@news6.svr.pol.co.uk>,
Philip Taylor <phil.taylor@bigfoot.com> wrote:
: I have constructed the following regular expression to validate scores:-
:
: /^\s*[0-9]{1,2}\s*\-\s*[0-9]{1,2}\s*$/
:
: it's purpose is to validate scores eg "13-2", but I also want to allow for
: spaces being entered within the score eg " 12 - 2".
I would write
if (/^\s* \d\d? \s*-\s* \d\d? \s*$/x) {
...;
}
or maybe
if (/^\s* # optional leading whitespace
\d\d? # one- or two-digit score
\s*-\s* # dash separator (with optional whitespace)
\d\d? # one- or two-digit score
\s*$/x) # optional trailing whitespace
{
...;
}
Greg
--
The power of accurate observation is commonly called cynicism by those who
have not got it.
-- George Bernard Shaw
------------------------------
Date: 31 Jul 2000 21:12:42 GMT
From: Tina Mueller <tina@streetmail.com>
Subject: Re: question about a Regular Expression
Message-Id: <8m4q49$5mcr3$5@ID-24002.news.cis.dfn.de>
hi,
Philip Taylor <phil.taylor@bigfoot.com> wrote:
> I have constructed the following regular expression to validate scores:-
> /^\s*[0-9]{1,2}\s*\-\s*[0-9]{1,2}\s*$/
> it's purpose is to validate scores eg "13-2", but I also want to allow for
> spaces being entered within the score eg " 12 - 2".
> It seems a bit long winded and I would be grateful for suggestions on how
> it's form/performance may be improved.
well, if you really want to allow things like
" 12 - 2" but not " 12 - 2 something else"
your regex can't be really hortened...
just a little bit:
/^\s*\d{1,2}\s*-\s*\d{1,2}\s*$/
that's the best i can think of now...
tina
--
http://tinita.de \ enter__| |__the___ _ _ ___
tina's moviedatabase \ / _` / _ \/ _ \ '_(_-< of
search & add comments \ \ _,_\ __/\ __/_| /__/ perception
please no answers via email unless followup is set to poster.
------------------------------
Date: Mon, 31 Jul 2000 18:17:06 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Question on sorting an array
Message-Id: <3985c2a2.662c$109@news.op.net>
In article <39858BE3.9E8DC9E7@gredos.cnb.uam.es>,
Federico Abascal <fabascal@gredos.cnb.uam.es> wrote:
>Hello,
>is there anyway to use the sort function in a way that you can know
>where the old indexes (positions) go.
Also see
http://www.plover.com/~mjd/perl/yak/hw2/slide005.html
for a couple of twists on this.
------------------------------
Date: Mon, 31 Jul 2000 19:32:45 GMT
From: ckeith@clara.net (Colin Keith)
Subject: Re: Quotes in regex?
Message-Id: <xvkh5.57$DT4.2119798@nnrp2.clara.net>
In article <8m4f1b$h2l$1@agate.berkeley.edu>, kuritzky@math.berkeley.edu (Eric Kuritzky) wrote:
>Yes. However, Mr. Keith wasn't asking about whether something matched
>or not. He wanted to know why one pattern took longer than another.
>According to the documentation, using $1, $', etc. causes _all_
>pattern matches to take longer.
Indeedy, back to the books for me for not remembering this, for posting code
that doesn't work (as someone pointed out with the trailing \s+). Thanks for
the replies (and sorry to have started a fight :)
Col.
---
Colin Keith
Systems Administrator
Network Operations Team
ClaraNET (UK) Ltd. NOC
------------------------------
Date: 31 Jul 2000 14:10:21 -0400
From: aperrin@demog.berkeley.edu (Andrew J. Perrin)
Subject: Re: regular expression
Message-Id: <ur98af9wy.fsf@demog.berkeley.edu>
bernd1615@my-deja.com writes:
> $_ =~ s/{5},(.*?)\,.*/$1/;
Take nothing, match it 5 times only, followed by a comma, followed by
any character until the following (unnecessarily backslashed) comma,
capture the previous, and replace the whole line with the captured
text....
>
> # i.e. I want to fetch everything between the 5th and the 6th comma
How about:
$foo = $1 if /(?:.*?,){5}(.*?),/;
(translation: exactly five instances of zero or more characters, each
instance followed by a comma, then capture the text from the character
immediately after the fifth of these instances, up to but not
including the next comma. This captured text will be put in $1 and,
therefore, into $foo.
--
----------------------------------------------------------------------
Andrew Perrin - Solaris-Linux-NT-Samba-Perl-Access-Postgres Consulting
aperrin@igc.apc.org - http://demog.berkeley.edu/~aperrin
----------------------------------------------------------------------
------------------------------
Date: Mon, 31 Jul 2000 18:23:38 GMT
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: regular expression
Message-Id: <sobh1anq9ft45@corp.supernews.com>
In article <8m4d0p$5re$1@nnrp1.deja.com>,
<bernd1615@my-deja.com> wrote:
: I got the following problem with regular expression
: I have comma delimited lines of a file,
Do you mean comma delimited or comma separated?
,comma,delimited,looks,like,this,
comma,separated,looks,like,this
: from which
: I want to extract some Information:
:
: $_ =~ s/{5},(.*?)\,.*/$1/;
:
: # i.e. I want to fetch everything between the 5th and the 6th comma
Why don't you use split to extract the fifth field?
# assumes comma separated
my $data = (split /\s*,\s*/, $line, 5)[4];
If that simple parser isn't sufficient (maybe you have commas in your
fields), use the Text::CSV module:
use Text::CSV;
my $csv = Text::CSV->new;
while (<>) {
unless ( $csv->parse($_) ) {
warn "$0: failed parse near '" .
$csv->error_input . "'\n";
next;
}
my $data = ( $csv->fields )[4];
# do whatever with $data
...;
}
Greg
--
In Christianity neither morality nor religion come into contact with reality
at any point.
-- Nietzsche
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 3861
**************************************