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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

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

Veteran / Moderator

Sep 14, 2012, 2:23 PM

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

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


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__ 778663 739008 240466 264865 181070 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