in reply to Why is the List upload with STDIN from a text file giving wrong result for mean?
In addition to the other fine advice you've received, I'd suggest you change this:
unless ( open(FILE, $filename) ) { print "Cannot open file \"$filename\"\n\n"; exit; }
to this:
open my $FILE, '<', $filename or die "Cannot open file '$filename': $!\n";
It's a much more common usage. I'd also change this:
# Sum of all elements in array: $sum=0; $sum=eval join '+',@array;
to this:
# Sum of all elements in array: $sum=0; $sum+=$_ for @array;
That way, you can avoid a potentially scary string eval. Since you're getting the data for your string from an external source, it's possible that someone might create a string that would let you compromise your system.
...roboticus
When your only tool is a hammer, all problems look like your thumb.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Why is the List upload with STDIN from a text file giving wrong result for mean?
by supriyoch_2008 (Monk) on Nov 02, 2012 at 14:23 UTC |