Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2014-04-18 22:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (472 votes), past polls