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

Re^4: Scope of $/

by Anonymous Monk
on May 26, 2016 at 01:52 UTC ( #1164156=note: print w/replies, xml ) Need Help??


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

:) 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:)

Replies are listed 'Best First'.
Re^5: Scope of $/
by Marshall (Abbot) on May 26, 2016 at 01:55 UTC
    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.
      Actually, the OP's code:
      while(<>){
      DOES use the $/="\n\n\n".

      My suggestion for the enclosing block is not strictly necessary for the posted code, but I think it is in good style, and enables protection in the event the program grows.

              This is not an optical illusion, it just looks like one.

        ++. Not strictly necessary for the posted code, but certainly necessary in the real code in view of the original question about the redefinition of $/ affecting other parts of the program (including apparently other modules). So it is most probably more than just good style, it is very likely to be absolutely needed for avoiding side effects.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2018-11-13 22:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My code is most likely broken because:
















    Results (159 votes). Check out past polls.

    Notices?