Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass Array of Hash of Arrays to Subroutine

Status
Not open for further replies.

CJason

Programmer
Oct 13, 2004
223
US
Ok, here's a good one...how do I pass an Array of Hash of Arrays to a subroutine? Do you just pass it like an array?

Code:
undef @AoHoA;
&mysub(\@AoHoA);

I've tried this, but I get the following error when attempting to use AoHoA in mysub:

"Can't coerce array into hash..."

It's obvious that I'm missing something. Do I need to do some sort of constructor on AoHoA before calling the sub???

Thanks!
 
I think I figured it out. The problem was actually in my_sub. I was doing:

@inAoHoA = @_;

Where I should have been doing:

$inAoHoA = @_;

 
actually you should be doing this:

Code:
my ($inAoHoA) = @_;

or:

Code:
my $inAoHoA = $_[0];

What you posted will result in $inAoHoA having a value equal to the length of the @_ array because you have assigned an array to a scalar.



------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Sorry, I tried to make things simple...and messed it up. I'm actually passing multiple things to the subroutine, so it's more like this:

($AoHoA,$this,$that) = @_;
 
OK... never mind then ;)

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top