in reply to Code review
++$Y{$y} if grep { $y eq $_ } @ARGV;
It does loose the short-circuiting aspect, but that's not likely to be relevant. But what if we take it a step further.
my $re; if ( @ARGV ) { my $pat = join "|", map quotemeta, @ARGV; $re = qr/^(?:$pat)\z/; } my %Y; while ( <> ) { my ( $y ) = ...; ++$Y{ $y } if $y && ( !$re || $y =~ $re ); }
Update: Hash simpler than regex.
my $re; my %valid; ++$valid{ $_ } for @ARGV; my %Y; while ( <> ) { my ( $y ) = ...; ++$Y{ $y } if $y && ( !%valid || $valid{ $_ } ); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Code review
by hv (Prior) on Mar 06, 2024 at 17:04 UTC | |
by ikegami (Patriarch) on Mar 07, 2024 at 05:27 UTC | |
by hv (Prior) on Mar 07, 2024 at 11:43 UTC |