Created
April 18, 2016 14:47
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!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