Skip to content

Instantly share code, notes, and snippets.

@michel47
Created April 18, 2016 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michel47/440541b963edd73eade4cda9f14bd33b to your computer and use it in GitHub Desktop.
Save michel47/440541b963edd73eade4cda9f14bd33b to your computer and use it in GitHub Desktop.
how to assign a hash table by slice (i.e setting a hash with both the key and value arrays)
#!perl
# how to assign a hash table in parallel
# using the whole slice !!!
# read more : http://perldoc.perl.org/perldata.html
#
# courtersy Michel Combes (@ Advancement of Civilization Effort Org.)
my %hash;
my @array = (1 .. 5);
my @keys = ('a' .. 'e');
printf "%s\n",join',',@array;
printf "%s\n",join',',@keys;
#%hash = ( map { $keys[$_] => $array[$_] } (0 .. $#array) );
@hash{@keys} = @array; # hash slice !
use YAML::Syck qw(Dump);
printf "%s\n",Dump(\%hash);
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment