Re: Question about variable scope
- From: "John W. Krahn" <someone@xxxxxxxxxxx>
- Date: Thu, 31 Jul 2008 05:57:18 GMT
nospam wrote:
Subject: Question about variable scope
Perhaps you should read "Coping with Scoping" at http://perl.plover.com/FAQs/Namespaces.html
In the code snippet below, why can't I access the $nntp variable, unless I
instantiate it within the ListGroups() subroutine?
Probably some "action at a distance" is causing it to become undefined.
#!/usr/bin/perl -w
#This nntp instance cannot be used in ListGroups()
#sub below:
# $nntp = Net::NNTP->new($newshost);
Here $nntp is a package variable and is visible anywhere inside the current package. Even if you had used a lexical variable it would be visible anywhere after this point in the program.
# $nntp->authinfo($username,$password);
.
.
.
sub ListGroups()
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
.
- Follow-Ups:
- Re: Question about variable scope
- From: Scott Bryce
- Re: Question about variable scope
- References:
- Question about variable scope
- From: nospam
- Question about variable scope
- Prev by Date: Japanese Girl > Megumi Okina
- Next by Date: Re: Textfile to array or hash
- Previous by thread: Question about variable scope
- Next by thread: Re: Question about variable scope
- Index(es):