in reply to calculate sum of numbers inside a text file

while (<>) { chomp; next unless length; if ($_ < 0) { push @negatives, $_; } else { push @positives, $_; } }

Update: This code was posted before the OP added code to his post.


Dave

Replies are listed 'Best First'.
Re^2: calculate sum of numbers inside a text file
by CR18 (Initiate) on Sep 27, 2015 at 05:01 UTC
    Thanks Dave.
      Can I put this while loop inside my array so that the array will first get the data from the file, and then run the calculation?

        No. Arrays are data containers. They do not contain while loops.


        Dave

        If you must do that, (then) should be able to, though overkill, via tie, object oriented model, etc.