Perl で、2 行目に k を 1 回だけ指定できる方法はありますか。
my %k = (a=>1, b=>2, c=>undef);
say for grep{!$k{$_}} keys %k;
Perl で、2 行目に k を 1 回だけ指定できる方法はありますか。
my %k = (a=>1, b=>2, c=>undef);
say for grep{!$k{$_}} keys %k;
Yes:
$b or say $a while ($a,$b) = each %k
But that's not any better (worse, IMO), so I'd stick with what you have.
CPAN モジュールにあるmapp
とを使用します。grepp
List::Pairwise
use List::Pairwise qw(grepp mapp);
my %k = (a=>1, b=>2, c=>undef);
say for mapp { $a } grepp { !$b } %k;
使用each
:
my %k = ( a => 1, b => 2, c => undef );
while ( my ($i, $j) = each %k ) { say $i unless $j };