in reply to Forcing Array Context

In this case you need to dereference the first parameter of push e.g
my %hash = ( foo => [ ] ); push @{ $hash{foo} }, "a string"; print $hash{foo}->[0]; __output__ a string
This is because push expects an array as the first parameter, and because hash values can only hold scalar values you have to dereference the value for push. For more info on dereferencing see. tye's References quick reference and perlreftut.
HTH

_________
broquaint

Replies are listed 'Best First'.
Re: Re: Forcing Array Context
by Anonymous Monk on Jun 25, 2003 at 09:36 UTC

    Thanks. One follow-up question: would the %hash = ( foo => []); blank the rest of %hash if it were used in a loop like I posted?

      Yep, %hash would be blanked. That particular line was just verbose initialization as push will auto-vivify the key and the array reference (i.e it will create both automatically). So assuming you're happy to initialize each key then a simple $hash{foo} = [] will suffice.
      HTH

      _________
      broquaint