Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

RE: use vars

by autark (Friar)
on Jul 17, 2000 at 03:12 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://22794]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2024-04-20 01:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found