Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re^3: How to safely use $_ in a library function?

by vsespb (Chaplain)
on Sep 17, 2013 at 13:17 UTC ( #1054437=note: print w/replies, xml ) Need Help??

in reply to Re^2: How to safely use $_ in a library function?
in thread How to safely use $_ in a library function?

Indeed, you're right, seems this does not work with goto.
  • Comment on Re^3: How to safely use $_ in a library function?

Replies are listed 'Best First'.
Re^4: How to safely use $_ in a library function?
by perl-diddler (Hermit) on Sep 17, 2013 at 19:39 UTC
    It fails on the assignment to $_ before the goto. The problem is there is no way to save off $_ and re-use it, making the central register, in perl, frozen/useless. Seems like a crack in the design -- I *rarely* got the message though I've reused that Vars code through many modules over a period of ~3 years.

    As much as anything, not running into it is a reflection of perl-programming style -- i.e. if one rarely, if ever, uses constants hard-coded in the text of the 'for' loop (I almost always use for with an array or such -- even if it is an array of constants -- which doesn't hit this problem).

    To answer the question of what happens if you call "for" in the target of the "goto", it overrides the global usage within the scope of the "for", then restores it. So the language *does* have "inherent" methods to do this, just, apparently, not explicit.

    One reason (among others,) for splitting the code was to have most of the code parsed at compile time and leave as little parsing to runtime as possible. Compare that to the alternative where the entire "main sub" was in-lined in the "eval". Then, not only could I probably get around it by using "for" as a means to assign to "$_", (i.e. for ([$sav, et other vals]) { overriden value of "$_" active here; set to be ptr-to the indirect array }), but I wouldn't need to use it in the first place. *ARG* (hitting head against wall)...

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1054437]
[Corion]: Hurr - as I'm running some not-so-static websites nowadays, maybe I really should implement a link checker that crawls these sites and checks that all internal links work ...
[Corion]: (in the sense of not returning 404 errors)
[1nickt]: Corion Surely you have one or more lying around?

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2017-10-18 11:25 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (244 votes). Check out past polls.