#!/usr/bin/perl -w use strict; use YAML::XS; my %all; open(INPUT,") { if ($_ =~ /^#/) { next } my ($src, $dest, $bytes) = split; $all{$src}{$dest}+=$bytes; } close(INPUT); my @reflist = sort { ${$$b}[2] <=> ${$$a}[2] } map \&buildlist($_), keys %all; foreach my $ref (@reflist) { print "${$$ref}[0] ${$$ref}[2]\n"; my @tmp=@{$$ref}[3]; #HERE foreach my $line (@tmp) { print "\t$line\n" } print Dump @tmp; } sub buildlist { my $site = $_; my @tmp; $tmp[0]=$site; $tmp[1]=\%{$all{$site}}; foreach (keys %{$tmp[1]}) { $tmp[2]+=${$tmp[1]}{$_} } @{$tmp[3]} = sort { ${$tmp[1]}{$b} <=> ${$tmp[1]}{$a} } keys %{$tmp[1]}; return \@tmp; # 0=site name, 1=hash ref, 2=total bytes, 3=sorted dest refs }