in reply to What does $::var means

It's basically just a shortcut for the package variable $main::var as demonstrated by:

package Foo; use strict; $::foo = "yayayaya"; + print $main::foo;

In your example the unqualified$var might be a different variable if it a lexical variable.

/J\

Replies are listed 'Best First'.
Re^2: What does $::var means
by kprasanna_79 (Hermit) on Jul 14, 2006 at 11:28 UTC
    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

      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\

      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