## Assuming the data provided is in the scalar $data
my %volsers=();
for my $line (split(/\n/, $data)){
my ($volser, $reads, $date) = split(/\,/,$line);
$volsers{$volser}{reads}+=$reads;
$volsers{$volser}{date}=$date;
#!/usr/bin/perl
use warnings;
my $line = mlist;
my $sum = 0;
# open the file
open(MLIST,"$line") or die "Unable to open LOG:$!\n";
# read it in one record at a time
while ($line = <MLIST>) {
my ($volser,$reads,$lwd) = split(/,/,$line);
printf "$volser $reads $lwd"
}
# close the file
close(MLIST);
Aaron,
I need to apologize for jumping groups.
I got frustrated when I couldn't get the code you gave me to mesh with
what I already had so I posted the same question to comp.lang.perl.misc
Apparently that's heavily frowned upon. Don't worry though, the guys
over there really let me have it.
Your code worked fine, I just didn't understand hashes like I should
have before posting.
Here's the end result.
Thanks again
#!/usr/bin/perl
use strict;
use warnings;
my $thresh = $ARGV[0];
my $filename = 'mlist';
my $sum = 0;
my $line='';
my $reads='';
my $volser='';
my $tmp_vol = '';
# open the file
open my $MLIST, '<', $filename or die "Unable to open $filename: $!\n";
# load the hash
my %hash=();
while (my $line = <$MLIST>) {
my ($volser, $reads, $date) = split(/,/,$line);
if ($tmp_vol eq ''){
$tmp_vol=$volser;
}
$hash{$volser}{reads}+=$reads;
$hash{$volser}{date}=$date;
if ($tmp_vol != $volser) {
if ($hash{$tmp_vol}{reads} <= $thresh) {
print "$tmp_vol $hash{$tmp_vol}{reads} $date";
}
$tmp_vol=$volser;
}
}
#close the file
close($MLIST);