Habit mostly. I like Streamer's default output better and I don't have to remember to print the result:
use Data::Dumper;
use Data::Dump::Streamer;
my @ListOfRecords = qw(1 a 2 b 3 c 4 d);
my %MappingOfRecords = reverse @ListOfRecords;
print Dumper \%MappingOfRecords;
Dump \%MappingOfRecords;
I think you are trying to create a hash where the second array element becomes a key and the first element becomes its value; and so on for fourth and third elements, etc. In that case, try this:
my @list = qw(a b c d e f g h);
my %hash = reverse @list;
print map { "$_ -> $hash{$_}\n" } keys %list;
#Prints:
h -> g
b -> a
d -> c
f -> e
No.
hbm and GrandFather's answer is the short and easy way to do it... and the more readable way.
PERL is not C. Mistaking it to be so really messes up things and makes you suffer bad performance, debugging and processing time.
hbm and GrandFather's answer is the short and easy way to do it... and the more readable way.
Yes, but both do something different than the code of the OP did. hbm and GrandFather both create a new hash - while the OP extends an existing hash. Now, if the hash was initially empty, this is the same thing. But we cannot decude that from the OP's snippet, so it would be quite bold to state what they did is the way of doing it. In fact, it's quite unPerlish to claim there exists the way of doing something.