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

Re^2: Scope of $/

by Anonymous Monk
on May 26, 2016 at 01:23 UTC ( [id://1164154]=note: print w/replies, xml ) Need Help??


in reply to Re: Scope of $/
in thread Scope of $/

The enclosing block is just noise :) unless you give it a name

Replies are listed 'Best First'.
Re^3: Scope of $/
by Marshall (Canon) on May 26, 2016 at 01:38 UTC
    That is not true. No name is required. The {} set the scope of the local. For my demo below, I used an "our" variable, package scope. A Perl Global like $/ acts similar. You cannot localize a "my" variable.

    I guess you can think of a local var as sort of like creating a stack of that variable. The local statement is like a "push" and when you exit the scope of the local, that is like a "pop". Rough analogy, but that is descriptive of the behavior.

    #!usr/bin/perl use warnings; use strict; our $x = 1; #a package variable { print "$x\n"; #prints 1 local $x = 99; print "$x\n"; #prints 99 } print "$x\n"; #prints 1, back to before the "local"

      :) in the OPs program, having  { local $/ ... } on the outside doesn't change the behavior of the program,

      therefore no benefit is realized ... so the extra {local} is just extra typing (noise),

      unless you add a name, like  sub StdinTriElReader{ local $/ = "\n\n\n"; ... } then its serves a purpose

      :D:D:)

        Oh, I see that post didn't use local $/= "\n\n\n"; in a some kind of read statement, I presume that was an oversight. Oops. A common use of local is so that you don't have to remember what say, $/ "was". Just re-define it with local and when scope finishes, it "pops" back to what it was. That was my main point.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2024-04-25 12:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found