Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: What does $::var means

by kprasanna_79 (Hermit)
on Jul 14, 2006 at 11:28 UTC ( [id://561194]=note: print w/replies, xml ) Need Help??


in reply to Re: What does $::var means
in thread What does $::var means

gellyfish,

But whats difference between

my $var and $::var

i know one is the package variable and other is lexical one. but is there any diference between them functionally


-Prasanna.K

Replies are listed 'Best First'.
Re^3: What does $::var means
by gellyfish (Monsignor) on Jul 14, 2006 at 11:39 UTC

    They are not the same variable. The lexical variable declared as my $var is only accessible within the scope within which it is defined, whereas the package variable $main::var is essentially accessible anywhere. The package variable appears in the global symbol table whereas the lexical variables have their own 'pad' so they occupy a different namespace.

    /J\

Re^3: What does $::var means
by Hofmator (Curate) on Jul 18, 2006 at 13:44 UTC
    For the difference between $var and $::var see the following code:
    package Foo; $var = "hello\n"; $::var = "bye\n"; print $var; # hello print $Foo::var; # hello print $::var; # bye print $main::var; # bye package main; print $var; # bye !! print $Foo::var; # hello print $::var; # bye print $main::var; # bye
    So - as mentioned elsewhere - $::var is equivalent to $main::var while $var refers to the $var variable in the current package.

    -- Hofmator

Log In?
Username:
Password:

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

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

    No recent polls found