Re: retrieving news messages



David Harmon <source@xxxxxxxxxx> wrote:
On Thu, 05 Jul 2007 12:25:20 -0700 in comp.lang.perl.misc, Joe Smith
<joe@xxxxxxxxx> wrote,
my $nntp = Net::NNTP->new('newsgroups.comcast.net', { Debug => 1} );
die "Unable to create NNTP object" unless $nntp;

You have got to get those two statements working before proceeding
any further.

It appears to me, that style of passing arguments to Net::NNTP->new
cannot work.


That is correct.

You are not calling it correctly.

The OPTIONS are "hash like", but you are passing a hash reference instead.


I see this code in Net/NNTP.pm:

sub new
{
my $self = shift;
my $type = ref($self) || $self;
my ($host,%arg);
if (@_ % 2) {
$host = shift ;
%arg = @_;
} else {
%arg = @_;
$host=delete $arg{Host};
}


The above looks wrong to me; I think it ought to be more like

if (not (@_ % 2)) {


If that were right, then it ought to be the original condition
but with the if and else blocks swapped.

The if block will be evaluated if there are an odd number of arguments,
the else block will be evaluated if there are an even number of args.

However, I'm still something of a Perl newbie, and am not quite sure
of all that I am looking at here. It appears that the constructor
fails to pick up the Host argument, but then it goes on to look for
the NNTPSERVER environment variable and use that, as documented.
I guess that everyone who got it to work had some such luck.

What do you all think?


You are calling new() with an even number of arguments (two), a
string and a hash reference.

Fix your call by passing an odd number of arguments instead
by losing the curlies:

my $nntp = Net::NNTP->new('newsgroups.comcast.net', Debug => 1 );


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
.