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/


Reply via email to