in reply to Re^16: How to store the output from foreach loop into variable/array without printing?
in thread How to store the output from foreach loop into variable/array without printing?
Hi ok ... $d_h refers ...
ok, good so far
I am looping through 6 columns ($six), and in each column, I will do ratio against two values ($tre and $tri).
And here is the problem, no ratio calculation is performed on the lines starting with printf, only a string is printed (printf prints a formatted string)
This tells me you did not call makeRatio (did not copy/paste makeRatio after UsedToBeJustDoWork and invoke makeRatio from within UsedToBeJustDoWork
Please do this and see what gets printed on stdout ... you should recognize what gets printed on stdout ... makeRatio replicates part of UsedToBeJustDoWork
So may I know if there is any article that explain that or..?
Well, perlintro and perlop and printf/sprintf
The free book Modern Perl (or http://learn.perl.org/books/beginning-perl/) might be easier to understand than perlop
If you use ppi_dumper it can help you understand the parts of a program. Here is the output of that portion
PPI::Statement PPI::Token::Word 'printf' PPI::Token::Quote::Single ''my $ratio%d_%d_%d = $$d_h[%d][%d] / $ +$d_h[%d][%d];'' PPI::Token::Operator '.' PPI::Token::Quote::Double '"\n"' PPI::Token::Operator ',' PPI::Token::Number '1' PPI::Token::Operator '+' PPI::Token::Symbol '$six' PPI::Token::Operator ',' PPI::Token::Number '1' PPI::Token::Operator '+' PPI::Token::Symbol '$tri' PPI::Token::Operator ',' PPI::Token::Number '1' PPI::Token::Operator '+' PPI::Token::Symbol '$tre' PPI::Token::Operator ',' PPI::Token::Symbol '$tri' PPI::Token::Operator ',' PPI::Token::Symbol '$six' PPI::Token::Operator ',' PPI::Token::Symbol '$tre' PPI::Token::Operator ',' PPI::Token::Symbol '$six' PPI::Token::Operator ',' PPI::Token::Structure ';'
So you see a "," comma does not terminate a statement, a statement is terminated by semicolon ";" which means all the symbols seperated by the comma operator are arguments to printf function
And is $ratio... the same as $ratio ...
I think you will have to tell me if they're the same :) Start a new file and employ ddumperBasic debugging checklist and compare the output you get (lesson courtesy of Basic debugging checklist and brian's Guide to Solving Any Perl Problem )
The books teach more about arrays and arrays of arrays, as does perldsc ...
You should spend more time with perlintro esp Perl variable types. By "spend time" I mean read it, type up at least ten ddumpering() programs , to learn what its trying to teach you, and equally important, to learn how to interpret ddumper output . The creatingfiles/typing part is important , babysteps (learning to crawl before you learn karate)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^18: How to store the output from foreach loop into variable/array without printing?
by Anonymous Monk on Mar 18, 2014 at 10:33 UTC |