> Actually Regex is taking more time instead of agrep. That's 
> why the idea of using either agrep or find.
> This is small input.txt which I am using it as a input file.
> If there is any other way of increasing the speed of same 
> Perl script, it is really required.

This has a chance of being faster. It uses Text::CSV::Simple--a wrapper
around Text::CSV_XS, which does the parsing in C for speed. Also, it
doesn't need any regular expressions. I think it's simpler code, too.

#!/usr/bin/perl -w

use Text::CSV::Simple;
use List::Util qw(sum);

my $parser = Text::CSV::Simple->new({ sep_char => "\t"});
$parser->want_fields(5,6,7,8,9,10,11); #make total column index 0
my @data = $parser->read_file('input.txt');

printf "Average of 'total' column: %.02f\n", column_average(0);
printf "Average of 'step1' column: %.02f\n", column_average(1);
printf "Average of 'step2' column: %.02f\n", column_average(2);

sub column_average {
    my ($idx) = @_;
    my $sum = sum map {$_->[$idx] if defined $_->[$idx]} @data;
    return $sum/scalar(@data);
}
__END__

You may be able to tweak even more speed out of it by using
Text::CSV::Simple's triggers to sum as you go instead of using
List::Util.

-- 
Mark Thomas 
Internet Systems Architect
_______________________________________
BAE SYSTEMS Information Technology 
2525 Network Place
Herndon, VA  20171  USA 


_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to