Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: using eval or equivalent to automatically generate my statements

by tobyink (Abbot)
on Dec 13, 2012 at 14:14 UTC ( #1008663=note: print w/ replies, xml ) Need Help??


in reply to using eval or equivalent to automatically generate my statements

You appear to be trying to emulate the concept of global variables with local variables. Why?

Global state is (generally) bad. Achieving global state using only local variables might be an interesting experiment, but it doesn't make global state any less bad.

perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'


Comment on Re: using eval or equivalent to automatically generate my statements
Re^2: using eval or equivalent to automatically generate my statements
by ISAI student (Scribe) on Dec 14, 2012 at 07:13 UTC

    Thank you for all yor help. Unofortunaely, I was granted very short time to do a rather thankless task. Theoretically, scratching it and start anew is the way to go. I have no management green light to do so, and the decision is not without reason. It took > 5 years of on-going user feedback to get where we wanted.

    I was hoping to see some really cool PERL magic, it may be for the best, but it would have been one cool metaprogramming feat...

      OK, so as not to disappoint...

      Introducing Acme::Asplode: it lets you drag your caller's lexical variables kicking and screaming into your sub. Ought to work in Perl 5.12+.

      Example usage...

      use 5.012; use strict; use warnings; use Acme::Asplode; sub bar { asplode($x, $y); # steal lexical variables from our caller! say $x; say $y; asplode @A, $z; # steal moar lexicals!!! say $z; $z++; # alter our caller's lexical variable!! say for @A; }; sub foo { my $x = 1; my $y = 2; my $z = 3; my @A = qw(a b c); bar(); say "Z is changed: $z"; } foo();

      Update: Acme::Asplode, renamed Acme::Lexical::Thief is now on CPAN.

      perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (15)
As of 2014-07-23 10:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (139 votes), past polls