I'm having difficulties compiling my script. The purpose of this script it to take numerical data from file #1 (input file), finding the largest, smallest, and the average of the said data and printing it to file #2 (output file).
I haven't attempted to go an further than the average because my script doesn't seem to recognize my data in the input file.
Input file as off right now just has the numbers 1-10. Here is my code:
#!/usr/bin/perl -w use strict; my @lines; my $ave; print "Enter an input file name: "; chomp (my $infile = <STDIN>); while (!(-e $infile)) { print "Invalid file name, Try again: "; chomp ($infile = <STDIN>); } print "\n"; print "Enter an output file name: "; chomp (my $outfile = <STDIN>); open (FIN,'<', $infile) or die "$!\n"; chomp (@lines = <FIN>); open (FOUT, '>', $outfile) or die "$!\n"; while (<STDIN>) { $ave = average(<FIN>); print FOUT $ave; } close FOUT; sub average { my $sum = 0; my $size = @lines; $sum = $sum + $_ foreach @lines; $sum / $size; } sub largest { my $max; for (@lines){ $max = $_ if !$max || $_ > $max; } $max }
I keep getting an error saying Illegal division by zero in bsad.pl at line 52. Please help me solve this mystery.
In reply to Importing Data and Exporting Data Issues by MikeyG
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |