Shawn H Corey wrote:
Uri Guttman wrote:
that modifies @ARGV so it is a bad idea. also it bypasses grep's purpose
of filtering a list. and as i posted, map is the correct solution

map is not the correct solution since it does not filter out those which
do not match the pattern.  Only grep can do that.

Did you actually try it?  I didn't think so.

$ perl -le'
@ARGV = map "link$_", 0, 1, "xx", "[]", 666, "99", -5;
print "\...@argv = @ARGV";
my @link_numbers = grep { /^link([0-9]+)/; $_ = $1; } @ARGV;
print "\...@argv = @ARGV\n" . @link_numbers . ": @link_numbers";
'
@ARGV = link0 link1 linkxx link[] link666 link99 link-5
@ARGV = 0 1   666 99
3: 1 666 99

$ perl -le'
@ARGV = map "link$_", 0, 1, "xx", "[]", 666, "99", -5;
print "\...@argv = @ARGV";
my @link_numbers = map /^link([0-9]+)/, @ARGV;
print "\...@argv = @ARGV\n" . @link_numbers . ": @link_numbers";
'
@ARGV = link0 link1 linkxx link[] link666 link99 link-5
@ARGV = link0 link1 linkxx link[] link666 link99 link-5
4: 0 1 666 99



John
--
The programmer is fighting against the two most
destructive forces in the universe: entropy and
human stupidity.               -- Damian Conway

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