in reply to How to store the output from foreach loop into variable/array without printing?

G'day hellohello1,

You've commented out the print statement inside the for loop but written the push statement outside (after) that loop.

You made much the same mistake which I pointed out in Re: Split and join a few days ago.

Use the strict and warnings pragmata, heed the messages they give, and fix your code accordingly. The first of those would have alerted to an issue with "push (@data1, $ratio1);".

If you indented your code to refect its logic, you probably could have seen what was wrong purely by inspection.

I also recommend you read and follow the earlier advice given by ++Anonymous Monk in Re: How to store the output from foreach loop into variable/array without printing?.

-- Ken

Replies are listed 'Best First'.
Re^2: How to store the output from foreach loop into variable/array without printing?
by hellohello1 (Sexton) on Mar 11, 2014 at 08:19 UTC
    Hi Kcott, yes I did add the strict pragmata, which prompt me that error. Have been trying to figure out how to work out my code by trying array method, etc.

    Pardon my limited knowledge, if I want to put push statement into the for loop, the $ratio1 will be added into the @data1 one by one until one loop is finished?

    I did try putting in the for loop, but I still couldn't get the output. So I try trial and error and end up writing to you guys for help and wonder if there is a better way to do it.

    Thanks :) I am looking into the earlier advice :)