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

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Hi rzward!

Just a short thought on using 'our' and 'use vars' everywhere... You could also do what use strict wants you to do: Fully qualify all the variables you use.

There's quite a difference between a true global variable (as defined with use vars or our or my at file scope), and something like $Package::variable (which is also global in the sense that it's accessible from outside of the package that defined it).

First and foremost, you'll keep fully qualified variables out of the namespace (read "way") of other modules/packages/namespaces.

BTW, has someone mentioned file scoped lexicals? That's my-definitions at the file level, outside of all subroutines, or BEGIN/END blocks. These are global to anything within the physical file they're defined in. Are they in any way more/less effective than globals? Gut knowledge anyone? If your scipt is monolithic (in one file) you could use those, too.

Most of your local variables will acually be lexically scoped variables (my-variables). If there are some spots in your code where the behavior of local is really needed, it's still fine to use a fully qualified variable.

Since your script was meant to support perl4, too, it's acutally quite likely that merely substituting local with my will break your code -- however, I'd still give it a quick shot to get some orientation how much of a problem you really have. I could also imagine writing a short script that analyzes the your code to help you determine where work is needed (isn't there some perl4_to_perl5 converter out there?).

For example, if there are any local variables that are solely used within one block, and never mentioned outside that block, you can safely make them my vars. If however, a variable is used in the caller of a function, AFTER the function returned (mind loops!) you probably can't just go ahead and define it as a my variable.

Also, you should check whether using local everywhere (in subroutines) was just a habit of the author of your script, or if it's been used in a determined way. If it was a habit, substituting with my will be less of a problem I'd assume.

It all depends on the size of your project, but in any way, you seem to have some work to do... ;)

So long,
Flexx


In reply to Re^2: local vs my by Flexx
in thread local vs my by rzward

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (13)
    As of 2014-11-24 20:42 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My preferred Perl binaries come from:














      Results (147 votes), past polls