Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Merging arrays into a hash

by marcink (Monk)
on Jun 15, 2001 at 15:50 UTC ( [id://88759]=note: print w/replies, xml ) Need Help??


in reply to Merging arrays into a hash

This will work:
#!/usr/bin/perl -w use strict; my @a = qw( 1 2 3 4 5 ); my @b = qw( a b c d e ); my %h = map { $a[$_] => $b[$_] } ( 0..$#a ); print "$_ => $h{$_}\n" foreach sort keys %h;


I'm still trying to find a way to do this without using indexes, though ;-)

Update: Yeah, the code japhy and Masem posted does exactly what I was looking for.
That's what happens when you're too far from your copy of The Camel Book ;-)

-mk

Replies are listed 'Best First'.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://88759]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2024-04-19 08:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found