Tuesday, 31 January 2023

Perl Data structures - Hash of Arrays

Method 1:

$HoA = {
    flintstones => [ "fred", "barney" ],
    jetsons => [ "george", "jane", "elroy" ],
    simpsons => [ "homer", "marge", "bart" ],
    };

foreach (keys %{$HoA})
{
    print "$_ => @{$HoA->{$_}}\n";
}


 Method 2: 

 %HoA = (
    flintstones => [ "fred", "barney" ],
    jetsons => [ "george", "jane", "elroy" ],
    simpsons => [ "homer", "marge", "bart" ],
    );

foreach (keys %HoA)
{
    print "$_ => @{$HoA{$_}}\n";
}

 

kaavannan blogspot

Labels:

0 Comments:

Post a Comment

Note: only a member of this blog may post a comment.

<< Home