use Data::Dumper;
use strict;
use warnings;
my %hash = (a => 3, b=> 4, c=>1 ,d=>7);
my @sels = qw(b c);
delete $hash{$_} foreach (@sels);
print Dumper \%hash;
####
use Data::Dumper;
use Benchmark qw(timethese);
use strict;
use warnings;
timethese(1000000, {
'loop' => \&s1,
'non-loop' => \&s2
});
sub s1 {
my %hash = (a => 3, b=> 4, c=>1 ,d=>7);
my @sels = qw(b c);
delete $hash{$_} foreach (@sels);
}
sub s2 {
my %hash = (a => 3, b=> 4, c=>1 ,d=>7);
my @sels = qw(b c);
delete @hash{@sels};
}
####
Benchmark: timing 1000000 iterations of loop, non-loop...
loop: 10 wallclock secs ( 9.84 usr + 0.03 sys = 9.87 CPU) @ 101276.08/s
(n=1000000)
non-loop: 8 wallclock secs ( 6.88 usr + 0.02 sys = 6.89 CPU) @ 145116.82/s
(n=1000000)