Re: retrieving news messages
- From: "A. Sinan Unur" <1usa@xxxxxxxxxxxxxxxxxxx>
- Date: Thu, 29 Nov 2007 12:18:42 GMT
David Harmon <source@xxxxxxxxxx> wrote in
news:13ksp20d0m9g2c5@xxxxxxxxxxxxxxxxxx:
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;
....
It appears to me, that style of passing arguments to Net::NNTP->new
cannot work. 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)) {
I know nothing about Net::NNTP, however, you are wrong here:
sub new
{
my $self = shift;
# $self now contains the class name or the
# object reference on which new was called.
# The argument list is shortened by one element.
my $type = ref($self) || $self;
my ($host,%arg);
if (@_ % 2) {
$host = shift ;
%arg = @_;
# if the argument list now contains an odd number
# of elements, shift the first one in to $host.
# After that, there would be an even number of
# arguments left. Use them as key => value pairs
# to form an arguments hash.
} else {
%arg = @_;
$host=delete $arg{Host};
# If there are an even number of arguments to begin with,
# interpret them as key => value pairs to from the
# arguments hash. Then, put the 'Host' argument in
# $host, at the same time removing it from %arg so that
# subsequent code does not need special cases.
}
At this point, I do not know who posted the original code, but look at
it:
my $nntp = Net::NNTP->new('newsgroups.comcast.net', { Debug => 1} );
The constructor is wrong. You can see that by realizing that the code
above would produce
%args = ( 'newsgroups.comcast.net' => { Debug => 1} );
from that constructor. Either of the following would work:
my $nntp = Net::NNTP->new('newsgroups.comcast.net', Debug => 1 );
or
my $nntp = Net::NNTP->new(
Host => 'newsgroups.comcast.net',
Debug => 1,
);
The documentation for Net::NNTP states:
"OPTIONS are passed in a hash like fashion, using key and value pairs."
I guess that everyone who got it to work had some such luck.
No, they read the documentation.
Sinan
--
A. Sinan Unur <1usa@xxxxxxxxxxxxxxxxxxx>
(remove .invalid and reverse each component for email address)
clpmisc guidelines: <URL:http://www.augustmail.com/~tadmc/clpmisc.shtml>
.
- Follow-Ups:
- Re: retrieving news messages
- From: David Harmon
- Re: retrieving news messages
- References:
- Re: retrieving news messages
- From: David Harmon
- Re: retrieving news messages
- Prev by Date: Re: retrieving news messages
- Next by Date: Re: SvUOK always fails on 64bit platform
- Previous by thread: Re: retrieving news messages
- Next by thread: Re: retrieving news messages
- Index(es):
Relevant Pages
|