in reply to Pushing a hashref into an array

Do you mean something along the lines of: foreach my $response ( @{ ref $address eq 'HASH' ? [ $address ] : $address } ) {... e.g.
use warnings; use strict; #use autodie; use Data::Dumper; my $hr = { qw/hk1 hv1 hk2 hv2/ }; my $ar = [ { qw/ak11 av11 ak12 av12/ }, { qw/ak21 av21 ak22 av22/ } ]; foreach (@$ar) { warn Dumper $_ } foreach (@{ ref $hr eq q/HASH/ ? [ $hr ] : $hr }) { warn Dumper $_ }
$ perl tst.pl $VAR1 = { 'ak12' => 'av12', 'ak11' => 'av11' }; $VAR1 = { 'ak22' => 'av22', 'ak21' => 'av21' }; $VAR1 = { 'hk2' => 'hv2', 'hk1' => 'hv1' };
A user level that continues to overstate my experience :-))

Replies are listed 'Best First'.
Re^2: Pushing a hashref into an array
by rastoboy (Monk) on Nov 11, 2009 at 12:49 UTC
    Thanks All, anon was right--it was a dumb scoping problem. And I'm red faced about the lack of quotes around HASH--I promise not to post questions again when I'm sleepy. Bloodnok: this is very cool:
    foreach (@{ ref $hr eq q/HASH/ ? [ $hr ] : $hr })
    I'd been wracking my brains for a way to do that as well :-)