[sf-perl] Plucking from a string

frosty biztos at mac.com
Thu May 22 18:35:24 PDT 2008


Here's a minor variation, which I think should be a little faster.

my $theline = "vvvbcd=7wwwbcd=88xxxbcd=999yyybcd=1000zzz";

my $TARGET = qr/(?:bcd=\d+)/; # safer to precompile the whole regex

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

-- f.

 
On Thursday, May 22, 2008, at 04:44PM, "yary" <not.com at gmail.com> wrote:
>On Thu, May 22, 2008 at 4:40 PM, Neil Heller <nheller at silcon.com> wrote:
>> You win the gold star!
>>
>> One question though.  In the line
>>
>>
>>
>> while ($theline =~ /($TARGETSTR\d+)/gi) {  print "$1\n"; }
>>
>>
>>
>> why did you use the parens "(" and ")" inside the real expression?
>
>to set $1
>
>see if the command "perldoc perlre" works on your system, it may be
>helpful in explaining.
>_______________________________________________
>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