$hash{$name}{$id}= $comment;
push @{$hash{$name}{$id}}, $comment; #this one has been commented out
####
my %hash;
my ($name, $id, $comment);
while(){
chomp;
my ($name, $id, $comment)=split;
$hash{$name}{$id}= $comment; #adding comment to related $name/$id..
#push @{$hash{$name}{$id}}, $comment; #create an anonymous array
#in case more than one $comment or other variables related to same $name/$id
}
##
##
Name1 12 firstname1 some more info
##
##
for my $key1(sort keys %hash){
print "$key1\t->$hash{$key1}\t"; #$hash{$key} hash reference,to access it dereference it.....
foreach $key2(sort keys %{$hash{$key1}}){
print "$key2\t->$hash{$key1}{$key2}\t\n";
}
}
##
##
use strict;
use warnings;
my %hash;
my ($name, $id, $comment);
while(){
chomp;
my ($name, $id, $comment)=split;
$hash{$name}{$id}= $comment;
#push @{$hash{$name}{$id}}, $comment;
}
print "Key\t\t Val\t\t Key\t Val\n";
print "---------------------------------------------------\n";
for my $key1(sort keys %hash){
print "$key1\t->$hash{$key1}\t";
foreach my $key2(sort keys %{$hash{$key1}}){
print "$key2\t->$hash{$key1}{$key2}\t\n";
}
}
use Data::Dumper;
print Dumper(\%hash);
__DATA__
Name1 12 firstname1
Name2 55 firstname2
Name3 20 firstname3
##
##