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

Re^2: Perl::Critic and Subroutines

by daugh016 (Initiate)
on Nov 27, 2012 at 22:26 UTC ( #1005936=note: print w/ replies, xml ) Need Help??

in reply to Re: Perl::Critic and Subroutines
in thread Perl::Critic and Subroutines

For both of the issues, I have tried to do your recommendation but then the functions stopped working. The was the problem I was having-- I cannot implement the recommendations without losing the functionality. Are there better ways to get the same output without the sloppy coding I have done?

Comment on Re^2: Perl::Critic and Subroutines
Replies are listed 'Best First'.
Re^3: Perl::Critic and Subroutines
by tobyink (Abbot) on Nov 28, 2012 at 08:17 UTC

    "I cannot implement the recommendations without losing the functionality."

    Well then, Perl::Critic is having the desired effect - steering you away from dodgy areas. :-)

    "Are there better ways to get the same output without the sloppy coding I have done?"

    Yes, others have pointed you towards PadWalker. That's a much better way for a sub to peek at its caller's variables. Much better in that it actually usually works. (Your current solution works through luck - because the variables you're peeking at are actually file-level.

    Here's an example using that.

    Better still would be to actually pass the subs the values they need as arguments, so they don't need to peek at their caller's variables...

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

      Thank you so much! This has helped tons!

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2016-02-14 08:10 GMT
Find Nodes?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?

    Results (462 votes), past polls