Consider a hash of arrays of arrays (HoAoA), where the keys are the urls and the associated value is a reference to an array of arrays:
use strict; use warnings; use Data::Dumper; my %hash; while (<DATA>) { chomp; my ( $url, $subject, $date ) = split /\t/; $hash{$url}->[0] //= $subject; push @{ $hash{$url}[1] }, $date; } local $" = ', '; print "Url|Title|Date(s)|Count\n"; for my $key ( keys %hash ) { print "$key|$hash{$key}->[0]|@{ $hash{$key}[1] }|" . scalar @{ $hash{$key}[1] } . "\n"; } print "\n", Dumper \%hash; __DATA__ http://www.perl.com Perl 01/05/10 7:44PM http://www.google.com/page?id=blah Google Search results for blah + 01/05/10 7:44PM http://www.google.com/page?id=blah Google Search results for blah + 05/10/12 8:12AM http://www.perl.com Perl 01/05/10 7:42AM http://www.perl.com Perl 01/10/10 9:44PMM
Output:
Url|Title|Date(s)|Count http://www.google.com/page?id=blah|Google Search results for blah|01/0 +5/10 7:44PM, 05/10/12 8:12AM|2 http://www.perl.com|Perl|01/05/10 7:44PM, 01/05/10 7:42AM, 01/10/10 9: +44PM|3 $VAR1 = { 'http://www.google.com/page?id=blah' => [ 'Google Search res +ults for blah', [ '01/05/10 7:44PM +', '05/10/12 8:12AM +' ] ], 'http://www.perl.com' => [ 'Perl', [ '01/05/10 7:44PM', '01/05/10 7:42AM', '01/10/10 9:44PM' ] ] };
In reply to Re: Organizing Links - Better to use hash, hash of arrays, or...?
by Kenosis
in thread Organizing Links - Better to use hash, hash of arrays, or...?
by CalebH
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |