#!/usr/bin/env perl
use strict;
use warnings;
use Net::NNTP;
my $nntp = Net::NNTP->new('newsgroups.comcast.net', { Debug => 1} );
my $USER = 'zaxfuuq';
my $PASS = 'redacted';
my $SERVER = 'newsgroups.comcast.net';
my $PORT = 119;
my $c = new Net::NNTP($SERVER, $PORT) or die $!;
$c->authinfo($USER,$PASS) or die $!;
$nntp->group('comp.lang.perl.misc')
or die "failed to set group c.l.p.m.\n";
my $msg_ids_ref = $nntp->newnews(time() - 24*60*60);
die "Failed to retrieve message ids\n" unless @{$msg_ids_ref};
open my $ofh, '>', 'articles.txt'
or die "Cannot open articles.txt: $!";
for my $msg_id (@{$msg_ids_ref}) {
$nntp->article($msg_id, $ofh)
or die "Failed to retrieve article $msg_id\n";
}
close $ofh;
__END__
I keep on trying this to make this script to run, without success. I think
I'm making some headway on it though. Instead of a grab bag of errors,
perl.exe is telling me that I have "an invalid argument" on this line:
my $c = new Net::NNTP($SERVER, $PORT) or die $!;
It takes a couple seconds for it to tell me that, so I think it might be
almost there. Ideas? Thanks in advance.
--
Wade Ward
Re: retrieving news messages
am 05.07.2007 02:35:36 von Bob Walton
Wade Ward wrote:
> #!/usr/bin/env perl
> use strict;
> use warnings;
> use Net::NNTP;
>
> my $nntp = Net::NNTP->new('newsgroups.comcast.net', { Debug => 1} );
> my $USER = 'zaxfuuq';
> my $PASS = 'redacted';
>
> my $SERVER = 'newsgroups.comcast.net';
> my $PORT = 119;
>
> my $c = new Net::NNTP($SERVER, $PORT) or die $!;
> $c->authinfo($USER,$PASS) or die $!;
>
> $nntp->group('comp.lang.perl.misc')
> or die "failed to set group c.l.p.m.\n";
> my $msg_ids_ref = $nntp->newnews(time() - 24*60*60);
> die "Failed to retrieve message ids\n" unless @{$msg_ids_ref};
>
> open my $ofh, '>', 'articles.txt'
> or die "Cannot open articles.txt: $!";
> for my $msg_id (@{$msg_ids_ref}) {
> $nntp->article($msg_id, $ofh)
> or die "Failed to retrieve article $msg_id\n";
> }
> close $ofh;
> __END__
> I keep on trying this to make this script to run, without success. I think
> I'm making some headway on it though. Instead of a grab bag of errors,
> perl.exe is telling me that I have "an invalid argument" on this line:
> my $c = new Net::NNTP($SERVER, $PORT) or die $!;
> It takes a couple seconds for it to tell me that, so I think it might be
> almost there. Ideas? Thanks in advance.
Well, did you bother to read the documentation for the Net::NNTP module?
If you do so, you will find you are calling the constructor
incorrectly. Also, you have already called the constructor once already
at that point (but without checking for success), so why are you calling
it again? Then you go on to not use the second constructor call anyway???
BTW, when I comment out the second constructor call and the line after
it that references it, your script otherwise verbatim generates a file
called "articles.txt" with the past day's clpm articles in it, which I
presume is what you want to do.
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
Re: retrieving news messages
am 05.07.2007 03:23:13 von Wade Ward
"Bob Walton" wrote in message
news:468c3cdb$0$16577$4c368faf@roadrunner.com...
> Wade Ward wrote:
> Well, did you bother to read the documentation for the Net::NNTP module?
> If you do so, you will find you are calling the constructor incorrectly.
> Also, you have already called the constructor once already at that point
> (but without checking for success), so why are you calling it again? Then
> you go on to not use the second constructor call anyway???
It would seem that I don't really know what a constructor is in perl without
reading up on it. _Programming Perl_ shows four different ways to invoke
constructors. Apparently the "my" is an lvalue modifier. Do I now have it
correct?
my $nntp = Net::NNTP->new('newsgroups.comcast.net', { Debug => 1} );
> BTW, when I comment out the second constructor call and the line after it
> that references it, your script otherwise verbatim generates a file called
> "articles.txt" with the past day's clpm articles in it, which I presume is
> what you want to do.
Then it sounds like I'm getting close. I'm still uncertain whether I have
to use authinfo or not. Right now, I have it commented out and perl.exe
tells me that it can't call method "group" on an undefined value here:
$nntp->group('comp.lang.perl.misc')
#!/usr/bin/env perl
use strict;
use warnings;
use Net::NNTP;
my $nntp = Net::NNTP->new('newsgroups.comcast.net', { Debug => 1} );
my $USER = 'zaxfuuq';
my $PASS = 'redacted';
my $SERVER = 'newsgroups.comcast.net';
my $PORT = 119;
#$nntp->authinfo($USER,$PASS) or die $!;
$nntp->group('comp.lang.perl.misc')
or die "failed to set group c.l.p.m.\n";
my $msg_ids_ref = $nntp->newnews(time() - 24*60*60);
die "Failed to retrieve message ids\n" unless @{$msg_ids_ref};
open my $ofh, '>', 'articles.txt'
or die "Cannot open articles.txt: $!";
for my $msg_id (@{$msg_ids_ref}) {
$nntp->article($msg_id, $ofh)
or die "Failed to retrieve article $msg_id\n";
}
close $ofh;
__END__
The authors of _Programming Perl_ are jokers. They have the three great
virtues of a programmer as laziness, impatience and hubris. I should fit
right in.
--
WW
Re: retrieving news messages
am 05.07.2007 04:33:12 von Tad McClellan
Wade Ward wrote:
> It would seem that I don't really know what a constructor is in perl without
> reading up on it.
Do you know what a constructor is in any other programming language?
It is the same thing in Perl, it creates a new instance (object).
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
Re: retrieving news messages
am 05.07.2007 06:05:47 von Sherm Pendley
Tad McClellan writes:
> Do you know what a constructor is in any other programming language?
>
> It is the same thing in Perl, it creates a new instance (object).
It's conceptually the same, but there are a few potential "gotchas" for
someone who's accustomed to other languages. In C++ and Java, for example,
"new" is a keyword, and the constructor method must share the name of the
class it belongs to.
By contrast, Perl constructors have no restrictions placed on their name
beyond those placed on function and method names in general. new() is used
often, but it's not required - the constructor could just as well be named
make_a_widget(). Nor is new() required to be a constructor - although you'd
seriously confuse people if you used it for something else.
(I know this isn't new to you Tad, I figured it was worth expanding on it
a bit for the OP's benefit.)
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
Re: retrieving news messages
am 05.07.2007 09:14:53 von Michele Dondi
On Wed, 4 Jul 2007 21:23:13 -0400, "Wade Ward"
wrote:
>Then it sounds like I'm getting close. I'm still uncertain whether I have
>to use authinfo or not. Right now, I have it commented out and perl.exe
That depends solely on whether you need to use authinfo to log in to
your news server when using your regular client or not.
>tells me that it can't call method "group" on an undefined value here:
>$nntp->group('comp.lang.perl.misc')
Because the constructor fails. As of how not to make it fail... I
don't know. In fact I've tried the script myself, changing the news
server with mine, which doesn't require authorization. I can't seem to
make the constructor succeed. Of course I can die() there, but it
baffles me that even with Debug => 1 no additional info is given. I'd
like to know *why* it fails but N::N's UI seems not to provide this
info.
Wade Ward wrote:
> Right now, I have it commented out and perl.exe
> tells me that it can't call method "group" on an undefined value here:
> $nntp->group('comp.lang.perl.misc')
Of course! If $nntp is undef, there is no possible way that $nntp->group()
is going to work. You are supposed to always check whether the constructor
was successfully created before attempting to use it.
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.
-Joe
Re: retrieving news messages
am 05.07.2007 23:25:51 von Wade Ward
"Joe Smith" wrote in message
news:7vKdnQay0Jo82BDbnZ2dnUVZ_qKqnZ2d@comcast.com...
> Wade Ward wrote:
>> Right now, I have it commented out and perl.exe tells me that it can't
>> call method "group" on an undefined value here:
>> $nntp->group('comp.lang.perl.misc')
>
> Of course! If $nntp is undef, there is no possible way that
> $nntp->group()
> is going to work. You are supposed to always check whether the
> constructor
> was successfully created before attempting to use it.
Thanks for your reply. Since this program is, for me and perl, the one
directly after hello world, I'm unable to do a lot of things that I could
with other syntaxes.
> 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.
Paul Lalli gave me this syntax for the constructor:
my $nntp = Net::NNTP->new('news.example.com', { Debug => 1} );
, and Bob Walton got it to work. The only thing it looks like you could
screw up is pasting in your news server. I've looked at OE and
newsgroups.comcast.net is how my other progs get news. Could this have
something to do with a comcast issue?
--
WW
Re: retrieving news messages
am 05.07.2007 23:32:21 von Wade Ward
"Tad McClellan" wrote in message
news:slrnf8om38.48n.tadmc@tadmc30.sbcglobal.net...
> Wade Ward wrote:
>
>> It would seem that I don't really know what a constructor is in perl
>> without
>> reading up on it.
>
>
> Do you know what a constructor is in any other programming language?
>
> It is the same thing in Perl, it creates a new instance (object).
To the extent that I know what a constructor is, I have it from MFC. It was
all integrated with the IDE, and if you wanted a method, you get it with
right-clicking and have the code stubouts waiting for you. With perl, I'm
operating off the command line and haven't even figured out how to get
perl.exe's objections into a text file.
--
Wade Ward
Re: retrieving news messages
am 06.07.2007 02:37:46 von Gunnar Hjalmarsson
Joe Smith wrote:
> You are supposed to always check whether the constructor
> was successfully created before attempting to use it.
>
> my $nntp = Net::NNTP->new('newsgroups.comcast.net', { Debug => 1} );
> die "Unable to create NNTP object" unless $nntp;
Yes, but that check should better include an investigation of the
contents of $!.
C:\home>type test.pl
#!/usr/bin/perl
use strict;
use warnings;
use Net::NNTP;
my $nntp = Net::NNTP->new('newsgroups.comcast.net', { Debug => 1} )
or die "Unable to create NNTP object: $!";
C:\home>test.pl
Unable to create NNTP object: Invalid argument at C:\home\test.pl line 5.
C:\home>
"Invalid argument". So, let's try with passing the Debug option as two
scalars instead of a hash ref:
C:\home>type test.pl
#!/usr/bin/perl
use strict;
use warnings;
use Net::NNTP;
my $nntp = Net::NNTP->new('newsgroups.comcast.net', Debug => 1 )
or die "Unable to create NNTP object: $!";
That seemed to work. From that debug info, there is especially one thing
that's interesting: "authentication required". It may or may not be due
to the ISP through which I'm accessing the Internet...
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
Re: retrieving news messages
am 06.07.2007 02:56:57 von Tad McClellan
Wade Ward wrote:
> With perl, I'm
> operating off the command line and haven't even figured out how to get
> perl.exe's objections into a text file.
perl.exe my_perl_program 2>messages.txt
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
Re: retrieving news messages
am 06.07.2007 04:14:14 von Scott Bryce
Wade Ward wrote:
> Could this have something to do with a comcast issue?
Could be. I am on Comcast, and I use news.comcast.net as the server name.
Re: retrieving news messages
am 06.07.2007 10:50:12 von Joe Smith
Gunnar Hjalmarsson wrote:
> Joe Smith wrote:
>> You are supposed to always check whether the constructor
>> was successfully created before attempting to use it.
>>
>> my $nntp = Net::NNTP->new('newsgroups.comcast.net', { Debug => 1} );
>> die "Unable to create NNTP object" unless $nntp;
>
> Yes, but that check should better include an investigation of the
> contents of $!.
No - not appropriate.
$! If used numerically, yields the current value of the C "errno"
variable, or in other words, if a system or library call fails,
it sets this variable.
When an object constructor fails, $! pretty much has nothing to do with
what the module is complaining about.
-Joe
Re: retrieving news messages
am 06.07.2007 11:18:35 von Gunnar Hjalmarsson
Joe Smith wrote:
> Gunnar Hjalmarsson wrote:
>> Joe Smith wrote:
>>> You are supposed to always check whether the constructor
>>> was successfully created before attempting to use it.
>>>
>>> my $nntp = Net::NNTP->new('newsgroups.comcast.net', { Debug => 1} );
>>> die "Unable to create NNTP object" unless $nntp;
>>
>> Yes, but that check should better include an investigation of the
>> contents of $!.
>
> No - not appropriate.
>
> $! If used numerically, yields the current value of the C
> "errno"
> variable, or in other words, if a system or library call
> fails,
> it sets this variable.
>
> When an object constructor fails, $! pretty much has nothing to do with
> what the module is complaining about.
Well, appropriate or not, but in this case it seems to have helped me
detect a problem that noone else has mentioned so far (the braces).
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
Re: retrieving news messages
am 06.07.2007 11:19:14 von Joe Smith
Wade Ward wrote:
> my $USER = 'zaxfuuq';
> my $PASS = 'redacted';
> my $SERVER = 'newsgroups.comcast.net';
That's the wrong format for $USER. Should be 'zaxfuuq@comcast.net'.
linux% cat nntp-test.pl
#!/usr/bin/env perl
use strict;
use warnings;
use Net::NNTP;
$|=1;
my $USER = 'myusername@comcast.net';
my $PASSWD = 'mypassword';
my $SERVER = 'news.comcast.net'; # aka news.comcast.giganews.com
my $GROUP = 'comp.lang.perl.misc';
my $FILE = 'articles.txt';
my $DAYS = 3;
my $nntp = Net::NNTP->new($SERVER, { Debug => 1} );
print "new($SERVER) returned $nntp\n";
my $time = time() - $DAYS*24*60*60;
print "Looking for articles since ".localtime($time)."\n";
my $msg_ids_ref = $nntp->newnews($time);
die "Failed to retrieve message ids\n" unless $msg_ids_ref;
open my $ofh, '>', $FILE
or die "Cannot open $FILE: $!";
for my $msg_id (@{$msg_ids_ref}) {
$nntp->article($msg_id, $ofh)
or die "Failed to retrieve article $msg_id\n";
}
close $ofh;
linux% perl nntp-test.pl
new(news.comcast.net) returned Net::NNTP=GLOB(0x980a010)
authinfo(chezinwap@comcast.net,***) succeeded
group(comp.lang.perl.misc) succeeded
Looking for articles since Tue Jul 3 02:14:28 2007
Failed to retrieve message ids
-Joe
Re: retrieving news messages
am 06.07.2007 17:45:20 von Michele Dondi
On Thu, 5 Jul 2007 17:25:51 -0400, "Wade Ward"
wrote:
>Thanks for your reply. Since this program is, for me and perl, the one
>directly after hello world, I'm unable to do a lot of things that I could
>with other syntaxes.
Perhaps you should take some intermediate step between hello world and
"this program", seriously.
On Fri, 06 Jul 2007 02:37:46 +0200, Gunnar Hjalmarsson wrote:
>> my $nntp = Net::NNTP->new('newsgroups.comcast.net', { Debug => 1} );
>> die "Unable to create NNTP object" unless $nntp;
>
>Yes, but that check should better include an investigation of the
>contents of $!.
Are you sure? Nothing in the docs for N::N show that $! could be set
to hold any error given by the constructor:
: This is the constructor for a new Net::NNTP object. "HOST" is the
: name of the remote host to which a NNTP connection is required. If
: not given then it may be passed as the "Host" option described
: below. If no host is passed then two environment variables are
: checked, first "NNTPSERVER" then "NEWSHOST", then "Net::Config" is
: checked, and if a host is not found then "news" is used.
>"Invalid argument". So, let's try with passing the Debug option as two
>scalars instead of a hash ref:
On Fri, 06 Jul 2007 11:18:35 +0200, Gunnar Hjalmarsson wrote:
>> When an object constructor fails, $! pretty much has nothing to do with
>> what the module is complaining about.
>
>Well, appropriate or not, but in this case it seems to have helped me
>detect a problem that noone else has mentioned so far (the braces).
Indeed in another post I also complained about either Net::NNTP's
constructor not to give appropriate debug into or its docs not to be
clear enough. OTOH inspecting the the source code of the module I see
no explicit setting of $! and I don't know if any of the stuff from
the used modules would do so either. Actually possible failures are:
OTOH I don't see how setting $! to some particular C library errno
would be a sane way to show the error. So that you actually detected a
problem seems to be a fortunate coincidence.
Michele Dondi wrote:
> On Fri, 06 Jul 2007 02:37:46 +0200, Gunnar Hjalmarsson
> wrote:
>
>>> my $nntp = Net::NNTP->new('newsgroups.comcast.net', { Debug => 1} );
>>> die "Unable to create NNTP object" unless $nntp;
>> Yes, but that check should better include an investigation of the
>> contents of $!.
>
> Are you sure?
No. And Joe seems to be sure that doing so is inappropriate...
>> "Invalid argument". So, let's try with passing the Debug option as two
>> scalars instead of a hash ref:
>
> Well, after all this does seem to be the case!
Or maybe it was just a coincidence.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
Re: retrieving news messages
am 06.07.2007 21:29:48 von Gunnar Hjalmarsson
Michele Dondi wrote:
> On Fri, 06 Jul 2007 11:18:35 +0200, Gunnar Hjalmarsson
> wrote:
>
>>> When an object constructor fails, $! pretty much has nothing to do with
>>> what the module is complaining about.
>> Well, appropriate or not, but in this case it seems to have helped me
>> detect a problem that noone else has mentioned so far (the braces).
> I don't see how setting $! to some particular C library errno
> would be a sane way to show the error. So that you actually detected a
> problem seems to be a fortunate coincidence.
Yes, now I think so too.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
Re: retrieving news messages
am 06.07.2007 21:30:01 von Wade Ward
"Michele Dondi" wrote in message
news:8ros83hh9iopuqiejj0r1f2309lub7emt6@4ax.com...
> On Thu, 5 Jul 2007 17:25:51 -0400, "Wade Ward"
> wrote:
>
>>Thanks for your reply. Since this program is, for me and perl, the one
>>directly after hello world, I'm unable to do a lot of things that I could
>>with other syntaxes.
>
> Perhaps you should take some intermediate step between hello world and
> "this program", seriously.
I thought that grabbing a usenet message in perl qualified as a baby step.
Apparently not.
--
Wade Ward
Re: retrieving news messages
am 06.07.2007 22:02:49 von Michele Dondi
On Fri, 6 Jul 2007 15:30:01 -0400, "Wade Ward"
wrote:
>> Perhaps you should take some intermediate step between hello world and
>> "this program", seriously.
>I thought that grabbing a usenet message in perl qualified as a baby step.
>Apparently not.
You can answer yourself the implicit question: would you have
succeeded writing such a program yourself, without anyone giving you a
ready made one? I've not learnt from exercises myself, but from actual
needs: however initially they were more of the kind of writing offline
web pages from "templates". (As a very beginner I invented my own
will, and my requirements were very simple.) And then managing files
on a local machine.
On Fri, 06 Jul 2007 21:24:37 +0200, Gunnar Hjalmarsson wrote:
>>> "Invalid argument". So, let's try with passing the Debug option as two
>>> scalars instead of a hash ref:
>>
>> Well, after all this does seem to be the case!
>
>Or maybe it was just a coincidence.
Well, *that* is the correct way to call the constructor. As can also
be seen from the code itself:
WW> I thought that grabbing a usenet message in perl qualified as a
WW> baby step. Apparently not.
it is. you just haven't followed the baby path. learning about basic
object construction and testing results is a baby step. learning how to
follow the docs for passing in a user/pw is a baby step. knowing what
the actual user/pw should be is a baby step. all baby steps. with the
amount of help you got in this one thread you should be a teenager by
now. :)
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
Re: retrieving news messages
am 06.07.2007 22:31:10 von Michele Dondi
On Fri, 06 Jul 2007 22:02:49 +0200, Michele Dondi wrote:
>web pages from "templates". (As a very beginner I invented my own
>will, and my requirements were very simple.) And then managing files
> On Fri, 06 Jul 2007 22:02:49 +0200, Michele Dondi
> wrote:
>
>>web pages from "templates". (As a very beginner I invented my own
>>will, and my requirements were very simple.) And then managing files
>
> Wheel. Apologies.
Getting your last wishes on record is a good thing - no need to apologize
for having written a will. :-)
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
Re: retrieving news messages
am 07.07.2007 08:51:16 von Michele Dondi
On Fri, 06 Jul 2007 21:03:41 -0400, Sherm Pendley wrote:
>>>web pages from "templates". (As a very beginner I invented my own
>>>will, and my requirements were very simple.) And then managing files
>>
>> Wheel. Apologies.
>
>Getting your last wishes on record is a good thing - no need to apologize
>for having written a will. :-)
Given that I actually have cancer... I'M TOUCHING MY NUTS! (I don't
know how common it is outside of Italy - but it is a common
"superstition" or better a ritual gesture, against adverse fate.)
"Michele Dondi" wrote in message
news:5pdu839fptjcrc8171utccfbtrmbf4ms12@4ax.com...
> On Fri, 06 Jul 2007 21:03:41 -0400, Sherm Pendley
> wrote:
>
>>>>web pages from "templates". (As a very beginner I invented my own
>>>>will, and my requirements were very simple.) And then managing files
>>>
>>> Wheel. Apologies.
>>
>>Getting your last wishes on record is a good thing - no need to apologize
>>for having written a will. :-)
>
> Given that I actually have cancer... I'M TOUCHING MY NUTS! (I don't
> know how common it is outside of Italy - but it is a common
> "superstition" or better a ritual gesture, against adverse fate.)
So long as it is you who do the touching...
P
Re: retrieving news messages
am 07.07.2007 12:05:37 von Michele Dondi
On Sat, 07 Jul 2007 08:56:28 GMT, "Peter Wyzl"
wrote:
>> Given that I actually have cancer... I'M TOUCHING MY NUTS! (I don't
>> know how common it is outside of Italy - but it is a common
>> "superstition" or better a ritual gesture, against adverse fate.)
>
>So long as it is you who do the touching...
Yeah, it doesn't work by other people's intervention. Strictly
personal! In fact:
: Opinions, it is well known, are like nuts... Everyone has his own.
: - Giorgio Gaber
"Michele Dondi" wrote in message
news:5pdu839fptjcrc8171utccfbtrmbf4ms12@4ax.com...
> On Fri, 06 Jul 2007 21:03:41 -0400, Sherm Pendley
> wrote:
> Given that I actually have cancer... I'M TOUCHING MY NUTS! (I don't
> know how common it is outside of Italy - but it is a common
> "superstition" or better a ritual gesture, against adverse fate.)
Out of curiosity, does the first name Michele make you male or female? A
person can't tell with romance languages. The statement has a different
connotation depending on the gender of the person saying it. Here, to ward
off bad luck, we knock on wood.
--
WW
Re: retrieving news messages
am 09.07.2007 20:10:19 von Charles DeRykus
On Jul 6, 12:04 pm, Michele Dondi wrote:
> On Fri, 06 Jul 2007 11:18:35 +0200, Gunnar Hjalmarsson
>
> wrote:
> >> When an object constructor fails, $! pretty much has nothing to do with
> >> what the module is complaining about.
>
> >Well, appropriate or not, but in this case it seems to have helped me
> >detect a problem that noone else has mentioned so far (the braces).
>
> Indeed in another post I also complained about either Net::NNTP's
> constructor not to give appropriate debug into or its docs not to be
> clear enough. OTOH inspecting the the source code of the module I see
> no explicit setting of $! and I don't know if any of the stuff from
> the used modules would do so either. Actually possible failures are:
>
> : return undef
> : unless defined $obj;
>
> and
>
> : unless ($obj->response() == CMD_OK)
> : {
> : $obj->close;
> : return undef;
> : }
>
> OTOH I don't see how setting $! to some particular C library errno
> would be a sane way to show the error. So that you actually detected a
> problem seems to be a fortunate coincidence.
>
The most likely errors are from the initial socket
connection. The inherited IO::Socket::INET and
friends seem to return $@ often by wrapping $!, eg,
$sock = IO::Socket::INET->new(PeerPort => 9999,
... or die "Can't bind : $@\n";
$@ = "connect: $!"; # from IO::Socket
# perl -MNet::NNTP -le 'Net::NNTP->new("non_news.com")
or die $@'
Net::NNTP: connect: Connection refused at -e line 1.
--
Charles DeRykus
Re: retrieving news messages
am 10.07.2007 15:17:10 von blazar
On 9 Lug, 19:31, "Wade Ward" wrote:
> > Given that I actually have cancer... I'M TOUCHING MY NUTS! (I don't
[snip]
> Out of curiosity, does the first name Michele make you male or female? A
> person can't tell with romance languages. The statement has a different
> connotation depending on the gender of the person saying it. Here, to ward
> off bad luck, we knock on wood.
A male. The feminine version -rarer- is Michela. And yeah... on wood
too. Or Iron. But nuts are more common... for about a half of the
population.
Michele
Re: retrieving news messages
am 10.07.2007 15:33:53 von blazar
On 9 Lug, 20:10, "comp.llang.perl.moderated"
sam-01.ca.boeing.com> wrote:
> The most likely errors are from the initial socket
> connection. The inherited IO::Socket::INET and
> friends seem to return $@ often by wrapping $!, eg,
Thank you for pointing out. However Net::NNTP's docs do not clearly
specify that, if at all, and perhaps should. Still, the particular
error returned in $! for the wrong argument was at most a fortunate
coincidence.
Michele
Re: retrieving news messages
am 29.11.2007 08:03:22 von David Harmon
On Thu, 05 Jul 2007 12:25:20 -0700 in comp.lang.perl.misc, Joe Smith 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. 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)) {
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?
Re: retrieving news messages
am 29.11.2007 12:11:21 von Frank Silvermann
"David Harmon"
Re: retrieving news messages
am 29.11.2007 13:16:22 von Tad McClellan
David Harmon
Re: retrieving news messages
am 29.11.2007 13:18:42 von 1usa
David Harmon
Re: retrieving news messages
am 29.11.2007 23:32:24 von Michele Dondi
On Wed, 28 Nov 2007 23:03:22 -0800, David Harmon
Re: retrieving news messages
am 30.11.2007 05:59:23 von David Harmon
On Thu, 29 Nov 2007 12:18:42 GMT in comp.lang.perl.misc, "A. Sinan
Unur" <1usa@llenroc.ude.invalid> wrote,
>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,
>);
Thanks for the explanation.
Nobody in the original thread figured it out. The documentation
could be more clear, instead of requiring a look at the source to
make sense of it. Nothing to do with a hash after all, just pairs
of argument names and values; I think mentioning hash just confused
the original poster.