supriyoch_2008:

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.


In reply to Re: Why is the List upload with STDIN from a text file giving wrong result for mean? by roboticus
in thread Why is the List upload with STDIN from a text file giving wrong result for mean? by supriyoch_2008

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.