Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: using 'my'

by sierrathedog04 (Hermit)
on Jun 21, 2001 at 19:40 UTC ( #90418=note: print w/ replies, xml ) Need Help??


in reply to using 'my'

I agree with all of those who say to 'use strict." However, using strict does not necessarily require the use of lexicals declared with my(). You may if you wish simply append main:: in front of all of your variables. That will declare your variables as global, which they already are anyway if you are not declaring them with my().

(Side note: Perl does not have true global variables. All variables exist only in the package in which they are defined. However, because main:: is the default package, variables that are non-lexical in main appear almost as if they are global.)

One point on 'use strict'. My brother has a magnificent e-commerce site written completely in Perl 5.00x It supports his entire family very nicely.

He does not 'use strict'! I told him that what he was doing was 'blasphemy.' He said that he does not view using Perl as a religious act. I cannot argue with success, but I will always use strict, and where possible I convert scripts written by others to strict when I maintain them.


Comment on Re: using 'my'
Re (tilly) 2: using 'my'
by tilly (Archbishop) on Jun 21, 2001 at 21:39 UTC
    Actually there are a number of truly global variables in Perl. For instance no matter what package you are in, $ENV, $^W, $_, etc are always the same.
      You are correct. Camel III's glossary says:
      In Perl, only certain special variables are truly global—most variables (and all subroutines) exist only in the current package.
      FWIW, those truly global variables are really all in the main package. The language parser acts as if those global variable names were prefixed with main:: if no package is specified, no matter what package directive is in scope at the time.

          -- Chip Salzenberg, Free-Floating Agent of Chaos

        I know that. An amusing side-effect is that if someone mistakenly tries to throw an our on, say, $_ and they are in any package other than main::, it will not work as they expect.

        This might be considered a bug.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (11)
As of 2014-07-30 10:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (230 votes), past polls