On Tue, Mar 2, 2010 at 1:46 PM, John W. Krahn <jwkr...@shaw.ca> wrote:

> raphael() wrote:
>
>>
>> Cool! I have to admit that is a "detailed" answer.
>> Also thanks for clearing out the differences between these two..
>>
>> ( my $ip = $last_page ) =~ m/([\d+\.]+)/;
>> ( my $ip ) = ( $last_page ) =~ m/([\d+\.]+)/;
>>
>> Just to clear out any misunderstanding "by above one"
>> I meant ( my $ip = $last_page ) =~ m/([\d+\.]+)/;
>> Now am I getting this right that this is the *wrong syntax* to get list
>> context.
>>
>
> Correct, there is no list context in that statement.  The parentheses are
> required because the =~ operator has higher precedence than the = operator.
>
>
>
>  Your post was very helpful since I didn't know about parenthesis (or lack
>> of
>> it) to capture values.
>>
>> I always did use parenthesis to capture values like
>> ( my $ip ) = $last_page =~ m/*(*[\d+\.]+*)*/g;
>>
>> Now I *know* this works
>> ( my $ip ) = $last_page =~ m/[\d+\.]+/g;
>>
>
> Again, the '+' character is not a valid IP address character so it should
> be removed from the character class and the '.' period character does not
> need to be escaped inside a character class.
>
> The capturing parentheses are *required* when you only want to return
> *part* of a pattern:
>
> ( my $ip ) = $last_page =~ /IP: *([\d.]+)/g;
>
> Or when you want to match a single pattern without the /g option:
>
> ( my $ip ) = $last_page =~ /([\d.]+)/;
>
>
>
>
>
> John
> --
> The programmer is fighting against the two most
> destructive forces in the universe: entropy and
> human stupidity.               -- Damian Conway
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
> Yup. Got it.

( my $ip ) = $last_page =~ m/[\d.]+/g

* parenthesis only if part of capture is required or without /g.
* + not inside character class since we don't have ip like 192+. (silly me).
* dot need not be escaped inside character class since it is no longer the
king (meta character) ?
* John is a helpful guy.

Reply via email to