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

Re: How to best pass on the context / wantarray?

by jdporter (Canon)
on Mar 26, 2006 at 23:32 UTC ( #539325=note: print w/ replies, xml ) Need Help??


in reply to How to best pass on the context / wantarray?

BrowserUK's response is good, I guess, but I want to offer the following because it uses an interesting but rarely used feature of perl.

sub which_obj { # examine the calling sub's 'wantarray': defined( (caller(1))[5] ) ? $_[0]->copy : $_[0] }
Then you can:
sub foo { . . . my $obj = $self->which_obj; . . . }
We're building the house of the future together.


Comment on Re: How to best pass on the context / wantarray?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (13)
As of 2014-09-22 16:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (198 votes), past polls