Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

(tye)RE: access to my variables from other subs

by tye (Sage)
on Oct 21, 2000 at 10:11 UTC ( [id://37787]=note: print w/replies, xml ) Need Help??


in reply to RE: RE (tilly) 2: access to my variables from other subs
in thread access to my variables from other subs

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")

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://37787]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-20 02:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found