Difference between $::variable and $variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rahatekarabhijeet
    New Member
    • Jan 2007
    • 55

    Difference between $::variable and $variable

    I want to know the difference between,

    1 . Declarations : $::varible and $varible

    2 . Calling of functions :
    $::functions_ou tput .= ::flatten_list( $item[1]); and
    $function_outpu t = flatten_list($i tem[1]);
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    The "::" is used to differentiate namespaces. In the absense of a package name before ::, it points to 'main', which is the perl program you initiated by name. I can see no reason to use that syntax. As far as I know, there is no difference between these two lines:

    $::functions_ou tput .= ::flatten_list( $item[1]);
    $function_outpu t = flatten_list($i tem[1]);

    Some test code:

    Code:
    $foo  = 'test';
    print $main::foo,"\n";
    print $::foo,"\n"; # same as above
    $foo .= ::foo();
    print $foo;
    sub foo {
        return 'foo';
    }
    the above code will not work if the "strict" pragma is used, making it particularly useless as far as current standards of perl programing are concerned.

    Comment

    Working...