From: "shawn wilson" <ag4ve...@gmail.com> > On Aug 16, 2011 9:48 PM, "John W. Krahn" <jwkr...@shaw.ca> wrote: >> >> Joseph L. Casale wrote: >>> >>> What is the correct way to quickly assign the result of a regex against >>> a cmdline arg into a new variable: >>> >>> my $var = ($ARGV[0] =~ s/(.*)foo/$1/i); >> >> >> my ( $var ) = $ARGV[0] =~ /(.*)foo/i; > > IIRC, that rederines $ARGV as well. I think (my $var = $ARGV) =~ /(.+)foo/; > might be better.
The code above doesn't use s/// but just m//, so it doesn't replace, but just match (and the 'm' is missing as usually). I have shown how can s/// can be used without changing the original variable, but in this case it could be more clear and preferable to just extract the part you want from $ARGV[0] without using s///. Octavian -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/