in reply to Re: Code review
in thread Code review
I would characterize the effect of the code as:
For each input line, process it and extract an id. When run with no arguments, count in %Y the number of times each id appears; when run with a list of ids as arguments, count only how often the specified ids appear (with multiplicity).
I suspect you have been misled by a misinterpretation of:
foreach (@ARGV) { ++$Y{$y}, next if $y eq $_; }
which is equivalent to:
foreach (@ARGV) { if ($y eq $_) { ++$Y{$y}; next; } }
(I assume the useless next is left over from cutting down the original code.)
This is an idiom I actually use quite commonly for compactness when parsing arguments:
while (@ARGV && $ARGV[0] =~ /^-/) { my $arg = shift @ARGV; last if $arg eq '--'; ($max = $arg || shift(@ARGV)), next if $arg =~ s{^-x}{}; $inject = 1, next if $arg eq '-i'; ++$debug, next if $arg eq '-d'; die "Unknown option '$arg'\n"; }
|
---|