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

RE: use vars

by autark (Friar)
on Jul 17, 2000 at 03:12 UTC ( #22794=note: print w/replies, xml ) Need Help??


in reply to use vars

When declaring a variable with 'my', you say that it is lexical, that is, the variable is only visible within the scope that you declared it.

If you on the other hand 'use vars', you say that "in this package I want to use variable $foo without having to write out it's fully qualified name ($main::foo). $foo will not be lexically scoped, but will be a global (a package variable).

In perl 5.6 you may also use the keyword 'our' to declare variables as globals, but with a visibility scope equal to a lexical variable. A global with lexical scope ? That did sound strange :) Writing 'our $foo' inside a block or subrutine will make $foo a global - but you may refer to it as $foo _only_ within the lexical scope. You can still refer to $foo outside the scope, but then you will have to fully qualify it as $main::foo (or $my_package::foo)

Autark

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2020-10-25 06:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (249 votes). Check out past polls.

    Notices?