Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

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

Replies are listed 'Best First'.
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1008663]
[shmem]: moment... lemme see...
[shmem]: Python 2.7.9
[shmem]: but! perl4 doesn't suck.
[LanX]: better try 3
[shmem]: that python stuff is none of my business.
[shmem]: but sometimes I have to debug things implemeted by "the other team" and stick their nose into their dirt.

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2018-03-20 18:33 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (257 votes). Check out past polls.