[sf-perl] Plucking from a string

Penkethman, John A john.a.penkethman at lmco.com
Fri May 23 10:36:54 PDT 2008


Good stuff.

But what's happening internally with 

while ($theline =~ /($TARGETSTR\d+)/gi) {  print "$1\n"; }


Within the while loop, is the matching expression "$theline =~
/($TARGETSTR\d+)/gi" returning one match at a time for each loop
iteration? It would seem so since it then assigns the result to $1 each
time. 

On the other hand, in frosty's

my $TARGET = qr/(?:bcd=\d+)/; 

print "$_\n" for ( $theline =~ /$TARGET/g );

the "$theline =~ /$TARGET/g" statement seems to be returning a whole
array, which then gets assigned to $_ one at a time. Why the difference?
Is there a difference? I think this is great, but I would not have
expected this behavior in the while loop.

Thanks,
jack


-----Original Message-----
From: sanfrancisco-pm-bounces+john.a.penkethman=lmco.com at pm.org
[mailto:sanfrancisco-pm-bounces+john.a.penkethman=lmco.com at pm.org] On
Behalf Of yary
Sent: Friday, May 23, 2008 7:47 AM
To: San Francisco Perl Mongers User Group
Subject: Re: [sf-perl] Plucking from a string

On Fri, May 23, 2008 at 7:30 AM, Neil Heller <nheller at silcon.com> wrote:
> Just one more question...
>
>
>
> In the line:
>
> while ($theline =~ /($TARGETSTR\d+)/gi) {  print "$1\n"; }
>
>
>
> why is the d+ escaped?

Try it without the backslash, and then try replacing the numbers in
the input with the letter "d". It's an eye opener!

Perhaps the command "perldoc perlre" isn't working on your system (bad
install?)- so try this page-
http://www.perl.com/doc/manual/html/pod/perlre.html
and search for "\d"

-y
_______________________________________________
SanFrancisco-pm mailing list
SanFrancisco-pm at pm.org
http://mail.pm.org/mailman/listinfo/sanfrancisco-pm


More information about the SanFrancisco-pm mailing list