Hi,

Background: there's a script that generates a standard-width text report by writing report into a file line by line. For most lines in the report it uses common format, but for some lines, based on some unpredictable runtime information, it needs to dynamically define a custom format. These custom formats have unpredictable "pictures", so it is impossible to pre-define all such formats in advance. Dynamic generation of custom formats is done via eval (as described in perlform). Since some lines end up using the same exact custom format, it would be beneficial to try to reuse it instead of generating and eval-ing the same string again and again.

Question: Other than maintaining a separate hash with created format names, what's the best & cheapest method of format caching here, i.e. determining if a format with a given name is already defined and available for assignment to the filehandle? I read that formats use their own namespace but I could not find any information on how to access it. Any help with this specific question would be greatly appreciated.


In reply to caching formats by hotpelmen

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.