I am trying to figure out a way to initialize a hash without having to go through a loop. I was hoping to use slices for that, but it doesn\'t seem to produce the expected resul
So, what you want is to populate the hash using an array for the keys, and an array for the values. Then do the following:
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my %hash;
my @keys = ("a","b");
my @values = ("1","2");
@hash{@keys} = @values;
print Dumper(\%hash);'
gives:
$VAR1 = {
'a' => '1',
'b' => '2'
};