I added open chomp and push, does it make sense? will the file be readable by the script now?

#!/usr/bin/perl -w open ( FH, 'faketext.txt' ); while ( <FH> ) { chomp; push @fake, $_; use strict; sub mean { my (@data) = @_; my $sum; foreach (@data) { $sum += $_; } return ( $sum / @data ); } sub median { my (@data) = sort { $a <=> $b } @_; if ( scalar(@data) % 2 ) { return ( $data[ @data / 2 ] ); } else { my ( $upper, $lower ); $lower = $data[ @data / 2 ]; $upper = $data[ @data / 2 - 1 ]; return ( mean( $lower, $upper ) ); } } sub std_dev { my (@data) = @_; my ( $sq_dev_sum, $avg ) = ( 0, 0 ); $avg = mean(@data); foreach my $elem (@data) { $sq_dev_sum += ( $avg - $elem )**2; } return ( sqrt( $sq_dev_sum / ( @data - 1 ) ) ); } my ( $data, @dataset ); print "Please enter data, separated by commas: "; $data = <STDIN>; @dataset = split( /[\s,]+/, $data ); print "Median: ", median(@dataset), "\n"; print "Mean: ", mean(@dataset), "\n"; print "Standard Dev.: ", std_dev(@dataset), "\n";

In reply to Re^4: Mean, Median and Mode by Noob@Perl
in thread Mean, Median and Mode by Noob@Perl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.