On Camel2, p122, it explains that formats "are declared rather than executed, so they may occur at any point in your program." I read that and decided to place my formats at the end of my script.
However, I discovered that where I could place a format seems to be constrained by the scope of the variables on the argument line.
If the vars on the argument line are global, I can put the format anywhere. But strict doesn't like global vars (and neither do I).
I remembered reading somewhere that I could think of a hash as providing a mini-namespace, so I declared a hash using <KBD>my</KBD> at the top of my script. I use values from the hash as args to the format. (See the code below.) That way, I can limit the number of "top-level" <KBD>my</KBD> variables.
However, I'm not really happy with this solution either. I'm wondering if there's actually a clever way to get around this problem.
Thanks,
Carl-Joseph
use strict; # # Hash to act as a "mini-namespace" for the format # my %GRID; &printit( "Line 1", "Total Income", "\$5.00" ); sub printit { my( $prefix_text, $left_text, $right_text ) = @_; ( $GRID{"prefix_text"}, $GRID{"left_text"}, $GRID{"right_text"} ) = + ( $prefix_text, $left_text, $right_text ); $~ = "GRID"; write; } # # Placing my formats here. # format GRID = -------------------------------------------------------- @>>>: @<<<<<<<<<<<<<<<<<<< | @<<<<<<<<<<<<<<<<<<< $GRID{"prefix_text"}, $GRID{"left_text"}, $GRID{"right_text"}; -------------------------------------------------------- . __END__
In reply to Format with Args at End of Script by Carl-Joseph
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |