What I am trying to do here is to print the results of the sub "add_row". It just creates a table, but the problem is, I need to call the sub routine as you see and perl executes the sub right there and ignores the $table_rows inside the while. How can I have the results of sub add_row used inside of the while so the template file can read it?I apologize since it must be me being too dumb, but I really can hardly make any sense of your question; however... on to the code:
If you nicely indent your code there should never be any need for such heavy comments...###################################################################### +###### sub print_form ###################################################################### +###### {
Huh?!? the "open or die" idiom is one of Perl's most charachteristic ones. But what does make you think that a simple print will make "run away now"?my $output_file = "template.sthml"; open(OUTPUT, "$output_file") || print "There is no file here, I'll run + away now!";
Also, and just as importantly, if that is to be an $output_file, isn't it that by any chance you could want to open it in write mode?!?
Slightly less importantly:
The &-form of sub call is obsolete and should never be used nowadays unless when one really know what he's doing.$table_rows = &add_row;
Are you sure it is an output file?!?while(<OUTPUT>) { $_=~s/<!-- (TBROWS) \/\/-->/$table_rows/g; print $_; }
One nice, fundamental, point about $_ is that it is the topicalizer and as such, the default argument of many functions and operators. Thus either
s/<!-- (TBROWS) \/\/-->/$table_rows/g; print;
Update: re-reading the code I realize that obviously the OP's problem may just be that he calls his sub out of the while loop, then he uses the return value of that sub, saved into a variable, every time it is needed inside the loop. OTOH there are IMHO bigger problems with his code, as signalled above.
In reply to Re: Sub Return Value Help
by blazar
in thread Sub Return Value Help
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |