in reply to Formating Text Files

if your data file is large, you might see some performance benefit from using a split instead of a more complicated regex:
# skip the header line, assuming it's the first line # otherwise, you'll have to check in the loop to see # if you have grabbed a number or a string my $header = <FILE>; my $total = 0; my $count = 0; while(<FILE>) { $total += (split('"', $_))[3]; $count++; } print "Average: ",$total/$count, "\n";
if you have multiple header lines inside the file, you will need to check in the loop to make sure that you skip the header lines.

Replies are listed 'Best First'.
Re: Re: Formating Text Files
by Anonymous Monk on Jun 20, 2002 at 16:19 UTC
    Thanks, good ideas! I was taking the 'scenic route' as I usually do. and making things to complicated.