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

Re: deferencing an hash in a subroutine

by zentara (Archbishop)
on Aug 20, 2010 at 15:06 UTC ( [id://856296]=note: print w/replies, xml ) Need Help??


in reply to deferencing an hash in a subroutine

Change
my %q=@_;
to something that processes @_ into my %q, like
#!/usr/bin/perl #A quick easy way to do it given @keys (array of keys) and @values #(array of values): #@hash{@keys} = @values; #This will set up the key/value pairs in %hash. #The real pain here is that the files have to be in sync otherwise #the data becomes a mess. #Given the above: my @MyArray1 = qw(5 4 3 2 1 6 9 11 12); my @MyArray2 = qw(cat dog mouse mice tree shrub sap unix max); if ( scalar(@MyArray1) != scalar(@MyArray2) ) { printf "Expecting two equal size arrays, but got the following:\n"; printf "MyArray1: %5d MyArray2: %5d\n"; die "Incorrect data setup"; } my %MyHash = (); while ( scalar(@MyArray1) ) { my $MyKey = pop(@MyArray1); my $MyData = pop(@MyArray2); $MyHash{$MyKey} = $MyData; } foreach my $MyKey (sort {$a <=> $b} keys %MyHash) { printf "%4d: %-s\n", $MyKey, $MyHash{$MyKey}; }

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2024-04-25 11:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found