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'
}
];