I did this:

> cat - >1.pl 1 > > cat - >2.pl 2 > > cat - >3.pl 3 > > perl foo.pl ?.pl 1.pl 1 Total value for the 1.pl : 1 2.pl 2 Total value for the 2.pl : 2 3.pl 3 Total value for the 3.pl : 3 Total value accumulated from all the files is:6>

Which is the correct total. So either you didn't test it or you didn't specify what you though the errant behavior was. Either will get you down votes.

If you format your code as follows it will be more readable to you and others. You can use ether tabs or spaces, Perl doesn't care.

foreach my $file (@ARGV) { open(FILE, "$file"); my $sum = 0; while (<FILE>) { chomp(); $sum+=$_; print "$file $_\n"; $total+=$sum; } print "Total value for the $file : $sum\n"; close( FILE ); }

Also; you already foreach through the files, why not do the copy in the same loop?

Please when you post code place <code> before and </code> after. These html tags put the code into the pretty little boxes you see in other posts. It also keeps the code from fouling up the browsers for those that read your posts. Please read Writeup Formatting Tips again and take it to heart.


s//----->\t/;$~="JAPH";s//\r<$~~/;{s|~$~-|-~$~|||s |-$~~|$~~-|||s,<$~~,<~$~,,s,~$~>,$~~>,, $|=1,select$,,$,,$,,1e-1;print;redo}

In reply to Re^5: Solution for your prof by starbolin
in thread <> diamond Operator by kocaweb

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.