Mailing List Archive
tlug.jp Mailing List tlug archive tlug Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]Re: [tlug] perl scoping problem
- Date: Wed, 4 Dec 2002 18:17:38 +0900
- From: Matt Doughty <wyndigo@example.com>
- Subject: Re: [tlug] perl scoping problem
- References: <156FB393C5E1A248B3CC24FA33EE9EB27C6297@example.com>
- User-agent: Mutt/1.4i
lexicals don't go in the symbol table. In layman's terms: my $foo; and $main::foo aren't the same thing. Get rid of the my, and your code should work. --Matt On Wed, Dec 04, 2002 at 12:09:24AM -0800, Brett Robson wrote: > > Hi all > > For those that remember me, I've just moved to Tokyo from Nagoya. I've been threating to attend a nomikai for a while now. > > > I've got a problem with Perl namespaces. I haven't used strict and packages before. I thought that variables in main are accessible from with packages. > > The following code doesn't do what I expect. I expect that $main::foo will have the value robbo. > > T > > > > $cat x.pl > #!/usr/bin/perl -w > use x1; > > my $foo; > my $bar = "brett"; > > > $foo = "robbo"; > > print "main\n"; > print "foo=".$foo; > print "\n"; > > &x1::set1(); > > print "back in main\n"; > print "foo=", $main::foo; > > print "\n"; > > -------------------------------------- > $ cat x1.pm > package x1; > use Exporter; > > sub set1 > { > print "set\n"; > print "foo=", $main::foo , "\n"; > print "foo=", $::foo , "\n"; > #print "foo=", $foo , "\n"; > print "leaving set\n"; > } > > 1; > > -------------------------------------- > > $ ./x.pl > main > foo=robbo > set > Use of uninitialized value in print at x1.pm line 7. > foo= > Use of uninitialized value in print at x1.pm line 8. > foo= > leaving set > back in main > Use of uninitialized value in print at ./x.pl line 19. > foo= > $ > -------------------------------------- > > > > > > ********************************************************** > TLUG server is hosted by Open Source Development Lab Japan > http://www.osdl.jp/ > ********************************************************** > > ========================================================== > To unsubscribe from this mailing list, > please see instructions at > http://www.tlug.jp/list.html > ========================================================== > >
- References:
- [tlug] perl scoping problem
- From: Brett Robson
Home | Main Index | Thread Index
- Prev by Date: Re: [tlug] DSL through Yahoo BB
- Next by Date: Re: [tlug] Repotec print server & Linux
- Previous by thread: [tlug] perl scoping problem
- Next by thread: RE: [tlug] perl scoping problem
- Index(es):
Home Page Mailing List Linux and Japan TLUG Members Links