in reply to Re^2: Reliably simulating 5.10 say()
in thread Reliably simulating 5.10 say()

But it leaves me worried that $_ is being used in say() as a global...

That's what $_ is; a global; and it's exactly what the real say does, along with a raft of other built-ins.

But it's a read-only reference, so it cannot harm anything.

So the question is, is that $_ referenced in the say() sub a global from the implicit $_ in the mainline loop, or not...?

I cannot parse the highlighted bit of that sentence.

Perhaps this will satisfy: There is only one $_ at any given time. It is the global $_.

Sometimes it is localised implicitely by some constructs (eg. for, while) and sometimes explicitly by user code; but all that means is that a copy of the previous value is kept somewhere and gets restored once the localisation ends.

Whenever you use $_; you get its current value, regardless of whether it has been localised in one or many previous scopes.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked

Replies are listed 'Best First'.
Re^4: Reliably simulating 5.10 say()
by hlc (Initiate) on Feb 08, 2015 at 15:06 UTC
    OK, thanks. I hear what you're saying, but why does the use of a global in a function leave me feeling dirty?

    Short of any other suggestions, this looks like the way to go.

    Thanks