which produces a list like%hash = map {$_ => undef } qw(city state country);
which is then turned into a hash. In fact, any other value than undef would do just as well, as it isn't actually used.( 'city' => undef, 'state' => undef, 'country' => undef )
But, it does so for every loop, just to test if $field is one of qw(city state country). That's a very inefficient way of doing it.
A better way would be to create the hash outside of the loop:
my %skip = map {$_ => undef } qw(city state country); foreach my $field (param) { next if exists $skip{$field}; foreach my $value (param($field)) { #process non blank thedata variable ... } }
Or, IMO perfectly acceptable for small skip lists and/or few parameters:
foreach my $field (param) { next if grep { $field eq $_ } qw(city state country); foreach my $value (param($field)) { #process non blank thedata variable ... } }
Note that I moved the test outside of the inner loop, as the result won't change for whatever values you get.
In reply to Re: Explanation of mapping and undef
by bart
in thread Explanation of mapping and undef
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |