On Thu, Jul 21, 2011 at 02:11:33PM -0700, Mike McClain wrote:
> Given the following snippet of code could someone explain to me
> why the linefeed gets included in $num?
> 
> mike@/deb40a:~/perl> perl -e'
> $str = "asdfggfh 987321qwertyyy\n";
> ($num = $str) =~ s/^.*?(\d+).*$/$1/;
> print $num;
> ' | hd

My thanks to Shawn, Jim, Rob & Dr. Rudd for their answers.
Now I not only know why I was getting the '\n' but 2 ways to avoid it.

($num = $str) =~ s/^.*?(\d+).*$/$1/s;
or
($num) = $str =~ /^.*?(\d+).*$/;

Danke,
Mike
-- 
Satisfied user of Linux since 1997.
O< ascii ribbon campaign - stop html mail - www.asciiribbon.org

-- 
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