http://qs1969.pair.com?node_id=24122


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