ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl-win32-users
perl-win32-users
Re: trouble accessing fully qualified $main::variable contents
by Ben Bullock other posts by this author
Jul 7 2008 5:38PM messages near this date
view in the new Beta List Site
Re: trouble accessing fully qualified $main::variable contents | RE: trouble accessing fully qualified $main::variable contents
2008/7/8 Greg Aiken <gaiken@[...].com> :
>  can anyone please explain why when I am in the subroutine,
>  and I attempt to print a variable that's been declared and assigned a value
>  in the main package - why I am unable to print the value of the main
>  package's variable (despite that I am using the fully qualified variable
>  name)?

Just to add to the discussion, because I didn't understand this
behaviour either, on the basis of

http://perl.plover.com/FAQs/Namespaces.html

I made a test script which might be useful for someone:

#! perl
use strict;
use warnings;

my $var = "value";
$main::var = "ninny-poo";
print "1: $var\n";
print "2: $::var\n";
print "3: $main::var\n";

our $var2 = "value-mungus";
print "1: $var2\n";
print "2: $::var2\n";
print "3: $main::var2\n";
$main::var2 = "ninny-poo";
print "1: $var2\n";
print "2: $::var2\n";
print "3: $main::var2\n";

&subroutine;

sub subroutine
{
    $main::var = "boo";
    print "1: $var\n";
    print "2: $::var\n";
    print "3: $main::var\n";
    $var2 = 'rottenapples';
    $main::var2 = "boo";
    print "1: $var2\n";
    print "2: $::var2\n";
    print "3: $main::var2\n";
}
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Greg Aiken
Andy Bach
Ben Bullock
Steve Howard
Jan Dubois

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved