in reply to Organizing Links - Better to use hash, hash of arrays, or...?
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' ] ] };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Organizing Links - Better to use hash, hash of arrays, or...?
by CalebH (Acolyte) on Oct 05, 2014 at 19:10 UTC |