Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
It looks like you are right. my does seem to be a better fit here. However, the following might be even more appropriate, given your description:
use constant EB => "\034";
That has the advantage that every knows it's a constant and not subject to change. Of course, if all you are doing is documenting, this may not be an option.
I have strict in use all the time, but I have only ever used my(), so I'm not clear on the difference.
local pushes the current copy of the variables value (if any) onto a stack and assigns a new value which is available to everything within the original scope of local. When that variable passes out of scope, the original value is pulled from the stack and restored. In practice, local is rarely needed, unless my cannot be used.

Global punctuation variables, for example, cannot be declared lexically with my and therefore must use local if you wish to constrain their scope.

open FILE, $somefile or die $!; { local $/; # slurp mode $foo = <FILE>; } close FILE;
The above snippet uses "slurp mode" to read the entire contents of a file into a scalar. local is in a block to ensure that the change to $/ does not affect other portions of the program (since $/ is global).

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just go the the link and check out our stats.


In reply to (Ovid) Re: my and local differences by Ovid
in thread my and local differences by HaB

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Domain Nodelet?
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this?Last hourOther CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (3)
    As of 2025-06-15 03:45 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?
      erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.