foreach my $k (@k) { $s =~ m/(.)$k(.)/ ; if (($1 ne "\0") || ($2 ne "\0")) { delete $h{$k} ; } ; }
You shouldn't use the variables $1 and $2 unless the match was successful because they retain their previous value if the match failed and so after the first successful match every key will be deleted.
for my $k ( @k ) { if ( $s =~ /\0$k\0/ ) { delete $h{ $k }; } }
In reply to Re^2: hash substrings
by jwkrahn
in thread hash substrings
by perlcat
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |