Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: i thought i knew 'our'...

by monk (Scribe)
on Jul 24, 2000 at 20:58 UTC ( #24122=note: print w/replies, xml ) Need Help??


in reply to i thought i knew 'our'...

Update: from the man pages i get: An `our' declares the listed variables to be valid globals within the enclosing block, file, or `eval'.
That is, it has the same scoping rules as a "my" declaration, but does not create a local variable.
HTH, monk

Replies are listed 'Best First'.
RE: Re: i thought i knew 'our'...
by autark (Friar) on Jul 24, 2000 at 21:11 UTC
    'our' and 'my' are two very different beasts. You can not substitute 'our' with 'my' or vice versa, take this as an example:
    use strict; { our $y; $y = 17; print "Inner: $y\n"; } our $y; print "Outer: $y\n";
    That will print:
    Inner: 17
    Outer: 17
    Now, if you substituted our with my (s/our/my/g) then it would print:
    Inner: 17
    Outer:
    ...and it would complain about use of uninitialized variable :-)

    Autark.

      you are right, what i meant was that our could be use to declare variables in the begining
      of a program like:
      #!/usr/bin/perl -w use strict; our($foo,@bar,%args); <- this was what i meant.
      Not to s/my/our/; as you pointed out. Sorry didn't explain myself quite right.
      monk

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2019-10-20 16:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?