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

Re: hash of arrays to a subrutine?

by Fang (Pilgrim)
on Jan 04, 2006 at 11:02 UTC ( [id://520845]=note: print w/replies, xml ) Need Help??


in reply to hash of arrays to a subrutine?

Hello and welcome tamaguchi.

One of the best starting point for references that I know of is the perlreftut man page, available online or on your system by issuing the perldoc perlreftut command. It should get you started on solid ground. If you need more infos, the book Learning Perl Objects, References and Modules is an excellent ressource, having 5 chapters about references, from introduction to tricks and recipe-like examples.

After that, if you still have some unanswered questions, there is perlmonks.org. But I'm sure you know about that one already.

Update: completely forgot about the technical part of your question about passing by reference a hash of arrays to a subroutine. Here's how you could do it.

my %HoA = ( foo => [ 'bar', 'baz' ], qux => [ 'thud', 'xyz' ], ); mysub(\%HoA); # pass a reference of the data structure sub mysub { my $hash_ref = shift; # or if you want to directly work with a hash # instead of a reference inside the sub you can use # my %HoA = %{ shift }; # Then you can do your stuff... }

If any of the above code looks unclear to you, start by reading the perlreftut doc, it should all suddenly make sense.

Once you're more at ease with references, you will certainly want to have a look at the Perl Data Structures Cookbook, as well as at the complete references documentation.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-04-24 20:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found