Eval-ing each time works ok, but it is molasses slow.

You don't have to use eval in order to create a new closure. As I recently pointed out, creating a closure doesn't even recompile the subroutine. So I wonder if your concern about speed is based on benchmarks or just an expectation on your part.

The drawback to the passing the variables is that is no longer quite as easy as envisioned: If you decide to display a new variable, you can't just change your template and be done, you now must change the code that passes in the hash or hashref to the display function.

A real code example would sure go a long way here. There are lots of ways to build something that knows about a lexical variable. I have a hard time imagining why passing in \%hash explicitly is such a hardship, but that is probably because I haven't seen any code that really shows what you are trying to do -- just the abstract problem that you think should be the solution.

$closure= maker( \%hashToUse ); $closure->(); $obj= Package->new( \%hashToUse ); $obj->Display(); use Package qw( setVar printVar ); setVar( %hashToUse ); printVar(); use Package qw( %Template ); $Template{var}= \%hashToUse; print $Template{output}; my $Print; use Package ( \$Print, \%hashToUse ); $Print->(); tie $output, "Package", \%hashToUse; print $output; tie \*STDOUT, "Package", \%hashToUse; print;

Okay, are any of those silly enough for you? (:

        - tye (but my friends call me "Tye")

In reply to (tye)RE: access to my variables from other subs by tye
in thread access to my variables from other subs by joe

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.