I’m guessing that — contrary to the title — “a list like X A B” is actually a hash in which the value corresponding to the key “X” is an anonymous array containing the elements “A” and “B”. If this guess is correct, the following should give the output required:
#! perl
use strict;
use warnings;
my %hash = ( X => [ qw( A B ) ],
Y => [ qw( C D E ) ],
Z => [ qw( F G H ) ], );
for my $key (sort keys %hash)
{
my $array_ref = $hash{$key};
print "$_ $key, " for @$array_ref;
}
Output:
14:29 >perl 737_SoPW.pl
A X, B X, C Y, D Y, E Y, F Z, G Z, H Z,
14:29 >
Hope that helps,
|