Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: looking for a perl way to build a hash

by code-ninja (Scribe)
on Jul 26, 2013 at 19:07 UTC ( #1046591=note: print w/ replies, xml ) Need Help??


in reply to looking for a perl way to build a hash

Everyone has put in their ways, I'll put mine too for consideration... :)

#!/usr/bin/perl use strict; use warnings; my $str1 = "1,2,3"; my $str2 = "a,b,c"; my ($k, %hash, $i); $i = 0; my @keys = split /,/, $str1; my @values = split /,/, $str2; foreach $k (@keys){ $hash{$k} = $values[$i++]; } print %hash;

I leave it up to you to print the hash in the formatted way


Comment on Re: looking for a perl way to build a hash
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (17)
As of 2014-09-23 12:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (221 votes), past polls