Hi tony ucdavis,
In case, you think those who commented before now really do not what to help, please think again. What you labour to do will not only be yours but would give you a kind of chip on your shoulder and a well of satisfaction. However, if you are still in doubt the following solve your problem:
use warnings;
use strict;
my %h;
chomp( my @arr = split /\s+?/, <DATA> );
my $key;
for (@arr) {
if ( !/[[:digit:]]/ ) {
$key = $_;
}
else {
if ( $h{$key} ) {
$h{$key} += $_;
}
else { $h{$key} = $_ }
}
}
print $_, q[ ], $h{$_}, q[ ], for sort keys %h;
__DATA__
a 1 b 3 c 5 a 2
But seriously, you need to know, how all that came together. So, please follow the advise given before this post. You would be glad you did. And welcome to the Monastery!!!
|