Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

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
    ...and it would complain about use of uninitialized variable :-)


      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.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (2)
As of 2022-07-01 11:16 GMT
Find Nodes?
    Voting Booth?
    My most frequent journeys are powered by:

    Results (98 votes). Check out past polls.