Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: How to pass multidimensional hashed arrays as reference to a subroutine?

by broomduster (Priest)
on Sep 01, 2008 at 09:50 UTC ( [id://708163]=note: print w/replies, xml ) Need Help??


in reply to How to pass multidimensional hashed arrays as reference to a subroutine?

When you define your anonymous array of hashes, it automagically creates the reference you need, so you just need to save it (the reference, that is) somewhere. Then you can pass it to a subroutine in the usual way.

use strict; use warnings; use Data::Dumper; my $array_of_hashes_ref = [ { h1key1 => "h1val1", h1key2 => "h1val2", }, { h2key1 => "h2val1", h2key2 => "h2val2", h2key3 => "h2val3", }, ]; print Dumper( $array_of_hashes_ref ); test_sub( $array_of_hashes_ref ); sub test_sub { my $aoh_ref = shift; print Dumper( $aoh_ref); }

Output:
$VAR1 = [ { 'h1key2' => 'h1val2', 'h1key1' => 'h1val1' }, { 'h2key2' => 'h2val2', 'h2key3' => 'h2val3', 'h2key1' => 'h2val1' } ]; $VAR1 = [ { 'h1key2' => 'h1val2', 'h1key1' => 'h1val1' }, { 'h2key2' => 'h2val2', 'h2key3' => 'h2val3', 'h2key1' => 'h2val1' } ];

Log In?
Username:
Password:

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

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

    No recent polls found