On 7/21/11 Thu Jul 21, 2011 2:11 PM, "Mike McClain" <mike.j...@cox.net> scribbled:
> 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 Because the newline is not matched as part of /^.*?(\d+).*$/ Therefore, it is not replaced and is left in the string. The .* does not gobble up the newline because . does not match newlines unless the /s modifier is used. The $ is an anchor and does not match any character. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/