CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate: Re: [CPS] Searching two-value hash array: Edit Log



FishMonger
Veteran / Moderator

Sep 14, 2012, 2:23 PM


Views: 2898
Re: [CPS] Searching two-value hash array

This should help you to work out a cleaner and more efficient solution.


Code
#!/usr/bin/perl 

use strict;
use warnings;
use Data::Dumper;

my %sum;

while ( my $line = <DATA> ) {
chomp $line;
my ($src, $dest, $bytes) = split(/\s/, $line);
my $key = join(' <-> ', sort($src, $dest));

$sum{$key} += $bytes;
}

print Dumper \%sum;


__DATA__
10.197.191.250:445 10.197.191.50:47766 778663
10.197.191.50:47766 10.197.191.250:445 739008
10.197.191.250:9090 10.197.191.101:4968 240466
10.197.191.101:4968 10.197.191.250:9090 264865
10.197.191.250:9090 10.197.191.45:27547 181070
10.197.191.45:27547 10.197.191.250:9090 532157



(This post was edited by FishMonger on Sep 14, 2012, 2:24 PM)


Edit Log:
Post edited by FishMonger (Veteran) on Sep 14, 2012, 2:24 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives