in reply to Constructing HoHoA from AoA

It looks like you are over-thinking the algorithm. :-)
my %hash; for my $nar ( @nar ) { my ( $key1, $key2 ) = split /\s*-\s*/, shift @$nar; push @{ $hash{ $key1 }{ $key2 } }, $nar; }

Replies are listed 'Best First'.
Re^2: Constructing HoHoA from AoA
by Limbic~Region (Chancellor) on Jan 02, 2006 at 07:07 UTC
    Anonymous Monk,
    Or perhaps not. The question doesn't go into specifics of the rest of the code so your solution could be a problem for the following reasons:
    • /\s*-\s*/ will match a single dash anywhere it appears as * means 0 or more'
    • shift @$nar is destructive
    • push @{ $hash{ $key1 }{ $key2 } }, $nar; will push a reference to the original not a copy so there could be spooky action at a distance depending on the rest of the code

    Cheers - L~R