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

Re: Is 'use vars' really obsolete?

by BrowserUk (Patriarch)
on Sep 18, 2017 at 23:47 UTC ( [id://1199635]=note: print w/replies, xml ) Need Help??


in reply to Is 'use vars' really obsolete?

Am I missing something?

Does this help?

package Foo; our $test = 12345; package Bar; print $Foo::test; $Foo::test='abcde'; package Foo; print $test;; 12345 abcde

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
In the absence of evidence, opinion is indistinguishable from prejudice. Suck that fhit

Replies are listed 'Best First'.
Re^2: Is 'use vars' really obsolete?
by Anonymous Monk on Sep 18, 2017 at 23:59 UTC
    package Foo; our $test = 12345; package Bar; print $test; __END__ 12345

      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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-25 13:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found