in reply to Re^2: Mean, Median and Mode
in thread Mean, Median and Mode
There are two forms of the open() function in Perl 5. The modern version takes three arguments, the filehandle to open or vivify, the mode of the filehandle, and the name of the file.
my $filename = "faketext.txt"; open my $fh, '<', $filename or die "Can't write to '$filename': $!\n";
After that use while loop and read the file content line by line and do the slite and call your mean,madian,etc functions like below,
while(my $eachLine = <$fh>) { chomp($eachLine); my @dataset = split( /[\s,]+/, $eachLine ); print "Median: ", median(@dataset), "\n"; print "Mean: ", mean(@dataset), "\n"; print "Standard Dev.: ", std_dev(@dataset), "\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Mean, Median and Mode
by 2teez (Vicar) on Jun 16, 2014 at 07:30 UTC | |
by vinoth.ree (Monsignor) on Jun 16, 2014 at 07:36 UTC | |
by Noob@Perl (Novice) on Jun 16, 2014 at 07:36 UTC | |
by Noob@Perl (Novice) on Jun 16, 2014 at 07:39 UTC | |
by vinoth.ree (Monsignor) on Jun 16, 2014 at 09:05 UTC |