Re: retrieving news messages



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>

.



Relevant Pages

  • Re: Mysql database not being updated
    ... sub set_min{ ... $host = shift; ... Here you set $host and $date to be two parameters passed into your ... does that query print out what you expect it to? ...
    (perl.beginners)
  • Mysql database not being updated
    ... sub set_min{ ... $host = shift; ... The code runs without any warnings/errors, but the database is not touched. ...
    (perl.beginners)
  • Re: Self referencing hash
    ... my $class = shift; ... sub type { ... You should also call it something better than HASH because the % ... one of the hash values an anonymous array. ...
    (perl.beginners)
  • code references - how to
    ... I have tried putting junk values in the hash values - sub ... So how do you create a code reference in this context, ... my $root = shift; ...
    (perl.beginners)
  • Re: hash on private member variable
    ... What does it mean to "use hash on a private member variable"? ... > sub new { ... > my $class = shift; ... Sinan Unur ...
    (comp.lang.perl.misc)