From: Edward WIJAYA <mailto:[EMAIL PROTECTED]> wrote:

: Suppose I have this Hash of array:
: 
: %HoA = {
:     A => ["fred", "barney"],
:     B => ["george", "jane", "elroy"],
: };

    I'll assume you mean a hash like this. Note
the use of parenthesis instead of braces.

my %HoA = (
    A => [ qw( fred barney ) ],
    B => [ qw( george jane elroy ) ],
);

 
: Is there any efficient way to append
: each of this HoA's array into one
: single array, e.g:
: 
: @name = ("fred", "barney", "george", "jane", "elroy");

use Data::Dumper 'Dumper';

my %HoA = (
    A => [ qw( fred barney ) ],
    B => [ qw( george jane elroy ) ],
);


#    Order doesn't matter

my @names;
push @names, @$_ foreach values %HoA;
print Dumper [EMAIL PROTECTED];


#   Or if order matters

# with sort
@names = ();
push @names, @{ $HoA{ $_ } } foreach sort keys %HoA;
print Dumper [EMAIL PROTECTED];

# with hash slice
@names = ();
push @names, @$_ foreach @HoA{ qw( B A ) };
print Dumper [EMAIL PROTECTED];

__END__


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to