in reply to array of arrays
This can be done using a hash.
#!/usr/bin/env perl use strict; use warnings; open my $fh, '<', 'test_file.txt' or die 'Can not open file'; my %data; while(<$fh>){ chomp $_; my ($key, $val) = split(/\|/, $_); $data{$key} += $val; } foreach my $key ( sort { $a <=> $b } keys %data ){ print "the total is: (".$data{$key}.")\n"; } exit;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: array of arrays
by Anonymous Monk on Jun 12, 2017 at 22:43 UTC | |
by huck (Prior) on Jun 12, 2017 at 23:04 UTC | |
by kevbot (Vicar) on Jun 13, 2017 at 05:33 UTC |
In Section
Seekers of Perl Wisdom