Re: Question about variable scope



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
.