Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Hash and arrays

by holli (Monsignor)
on Aug 04, 2005 at 08:33 UTC ( #480718=note: print w/replies, xml ) Need Help??


in reply to Hash and arrays

You mean like this?
my @k = ("a", "b", "c"); my @v = (1, 2, 3); my %h = map { $k[$_] => $v[$_] } (0..$#k);


holli, /regexed monk/

Replies are listed 'Best First'.
Re^2: Hash and arrays
by thinker (Parson) on Aug 04, 2005 at 08:48 UTC

    Or, in a similar way, use a hash slice to populate the hash

    #!/usr/bin/perl use strict; use warnings FATAL => "all"; use Data::Dumper; my @k = ("a", "b", "c"); my @v = (1, 2, 3); my %h; @h{@k} = @v; print Dumper \%h; __END__ output $VAR1 = { 'c' => 3, 'a' => 1, 'b' => 2 };

    cheers

    thinker

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://480718]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2018-07-21 13:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (449 votes). Check out past polls.

    Notices?