On 11-07-21 05:11 PM, 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
00000000  39 38 37 33 32 31 0a                              |987321.|
00000007

Thanks,
Mike

Try:

$ perl -e'
$str = "asdfggfh 987321qwertyyy\n";
($num = $str) =~ s/^.*?(\d+).*$/$1/s;
print $num;
' | hd

See `perldoc perlre` and search for /Modifiers/. Read the section on the /s modifier.


--
Just my 0.00000002 million dollars worth,
  Shawn

Confusion is the first step of understanding.

Programming is as much about organization and communication
as it is about coding.

The secret to great software:  Fail early & often.

Eliminate software piracy:  use only FLOSS.

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