Hola, I am trying to map two fixed and known lenght lists into a hash, preferably without using variables.
I want to replace myfunc below with a short but legible bit of code, the last attempt below ends up using $_, @_ and %_ which is a bit mean.
Any better offers??
my @usual = qw ( data email stuff ); #--- fixed length
my $i = 0;
my %hash;
my @input = (
#--- rather have no function
{ username => 'fred1', myfunc ( 12, 56, 78 ) },
#--- no use if have to reset $i
{ username => 'fnerk', map { $usual[ $i++ ] => $_ } (33, 44, 55) }
+,
#--- hmm
{ username => 'aargh', map { @hash{@usual} = @$_; %hash } [ 33, 44
+, 55 ] },
#--- longwinded
{ username => 'fnerk', map { $tmp = shift @usual;
push @usual,$tmp; $tmp, $_ } (33, 44, 55) },
#--- heinous
{ username => 'aargh', map { @_{ @usual } = @$_; %_ } [ 33, 44, 55
+ ] },
);
sub myfunc {
my %flib;
@flib{ @usual } = @_;
return %flib;
}
for ( @input ) {
my %local = %$_;
for (sort keys %local ) {
print "key : $_ : val : $local{$_} : ";
}
print "\n";
}