Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re^3: Is 'use vars' really obsolete?

by AnomalousMonk (Chancellor)
on Sep 19, 2017 at 00:56 UTC ( #1199639=note: print w/replies, xml ) Need Help??

in reply to Re^2: Is 'use vars' really obsolete?
in thread Is 'use vars' really obsolete?

our has lexical scope.

c:\@Work\Perl\monks>perl -wMstrict -le "{ package Foo; our $test = 12345; } ;; { package Bar; print 'fully qualified: ', $Foo::test; } " fully qualified: 12345
Try the statement
    print 'unqualified: ', $test;
in package Bar.

BTW: Perl 5.14 introduced the neater (IMHO)  package NAMESPACE BLOCK syntax, so the code above could now look like

package Foo { our $test = 12345; } package Bar { print 'fully qualified: ', $Foo::test; }

Update: Note that package also has lexical scope!

Give a man a fish:  <%-{-{-{-<

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1199639]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2017-11-19 13:18 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (281 votes). Check out past polls.