Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2018-04-20 00:23 GMT
Find Nodes?
    Voting Booth?