For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > May 2004 > Re: noob question: Trying to extract part of a string in a variableto









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: noob question: Trying to extract part of a string in a variableto
John W. Krahn

2004-05-19, 8:31 pm

Paul Lalli wrote:
>
> On Wed, 19 May 2004, cayenne wrote:
>
>
> The parens around $user_id force the binding operation of =~ to be
> evaluated in list context. This is done because a pattern match in list
> context returns a list of all of the captured matches (ie, the things that
> go into $1, $2, etc). This is a shorthand way of writing the two
> statements:
>
> $mail_address =~ m/([\w.-+=]+)@/
> my $user_id = $1;


They are not the same at all. If the match fails the first will set
$user_id to undef but your version will set $user_id to the contents of
a previously successful match's capturing parentheses or ''.




John
--
use Perl;
program
fulfillment
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com