On 22/07/2011 15:25, Mike McClain wrote:
On Fri, Jul 22, 2011 at 01:54:57AM +0100, Rob Dixon wrote:
As others have noted, /./ without the /s modifier matches any character
but newline, so the regex matches only up to just before the "\n". But
your code would be better written as
use strict;
use warnings;
my $str = "asdfggfh 987321qwert99yyy\n";
my ($num) = $str =~ /(\d+)/;
print $num;
Hi Rob,
Thank you for your response and seeing how you moved the parens()
taught me something
The point is that there is no need to write a substitution to delete
everything around the part of the string you are interested in. If you
put a match in list context (which is what the parentheses around $num
do) it will return all of the captured strings. So /(\d+)/ will find the
first sequence of digits in the string and assign it to $num.
but I subscribe to the list and it's customary to keep replies on the
list unless what you have to say shouldn't be broadcast.
I have been posting to beginners@perl.org for over ten years now, and am
aware of what is customary. I and most others do a 'Reply all' so that
the OP gets a personal response as well as revealing the dialogue to the
community. That is what I did in this case - you will see my reply on
the list if you look.
Rob
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/