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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.