Hi, I'd suggest you build a hash keyed by name and then a sub-hash per name keyed by the date, with the values stored in an array. (To lovers of acronyms this would be a HOHOA (hash of hashes of arrays)).
Output:use strict; use warnings; use feature 'say'; my %result; for my $line (<DATA>) { chomp $line; my ( $name, $date, $val ) = split ' ', $line; push @{ $result{ $name }{ $date } }, $val; } for my $name ( keys %result ) { say $name; for my $date ( keys %{ $result{ $name } } ) { say "\t$date: @{ $result{ $name }{ $date } }"; } } __DATA__ nick 20/5/1950 one john 18/2/1980 two nick 19/6/1978 three nick 20/5/1950 four nick 12/9/2000 five john 15/6/1997 six nick 20/5/1950 seven
$ perl 1221691.pl john 15/6/1997: six 18/2/1980: two nick 19/6/1978: three 20/5/1950: one four seven 12/9/2000: five
Hope this helps!
In reply to Re: which data structure do I need for this grouping problem?
by 1nickt
in thread which data structure do I need for this grouping problem?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |