f



retrieving news messages

#!/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 


0
Wade
7/4/2007 11:36:18 PM
comp.lang.perl.misc 33233 articles. 2 followers. brian (1246) is leader. Post Follow

38 Replies
9402 Views

Similar Articles

[PageSpeed] 37

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
0
Bob
7/5/2007 12:35:36 AM
"Bob Walton" <see.sig@rochester.rr.com> 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


0
Wade
7/5/2007 1:23:13 AM
Wade Ward <invalid@invalid.nyet> 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/"
0
Tad
7/5/2007 2:33:12 AM
Tad McClellan <tadmc@seesig.invalid> 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
0
Sherm
7/5/2007 4:05:47 AM
On Wed, 4 Jul 2007 21:23:13 -0400, "Wade Ward" <invalid@invalid.nyet>
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.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
0
Michele
7/5/2007 7:14:53 AM
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

0
Joe
7/5/2007 7:25:20 PM
"Joe Smith" <joe@inwap.com> 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 


0
Wade
7/5/2007 9:25:51 PM
"Tad McClellan" <tadmc@seesig.invalid> wrote in message 
news:slrnf8om38.48n.tadmc@tadmc30.sbcglobal.net...
> Wade Ward <invalid@invalid.nyet> 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 


0
Wade
7/5/2007 9:32:21 PM
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: $!";

C:\home>test.pl
Net::NNTP>>> Net::NNTP(2.23)
Net::NNTP>>>   Net::Cmd(2.26)
Net::NNTP>>>     Exporter(5.58)
Net::NNTP>>>   IO::Socket::INET(1.27)
Net::NNTP>>>     IO::Socket(1.28)
Net::NNTP>>>       IO::Handle(1.24)
Net::NNTP=GLOB(0x1a310b4)<<< 200 News.GigaNews.Com
Net::NNTP=GLOB(0x1a310b4)>>> MODE READER
Net::NNTP=GLOB(0x1a310b4)<<< 480 authentication required
Net::NNTP=GLOB(0x1a310b4)>>> QUIT
Net::NNTP=GLOB(0x1a310b4)<<< 205 goodbye

C:\home>

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
0
Gunnar
7/6/2007 12:37:46 AM
Wade Ward <invalid@invalid.nyet> 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/"
0
Tad
7/6/2007 12:56:57 AM
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.
0
Scott
7/6/2007 2:14:14 AM
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
0
Joe
7/6/2007 8:50:12 AM
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
0
Gunnar
7/6/2007 9:18:35 AM
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";

print "authinfo($USER,***) ";
$_ = $nntp->authinfo($USER,$PASSWD) ? 'succeeded' : 'failed';
print "$_\n";

print "group($GROUP) ";
$_ = $nntp->group($GROUP) ? 'succeeded' : 'failed';
print "$_\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
0
Joe
7/6/2007 9:19:14 AM
On Thu, 5 Jul 2007 17:25:51 -0400, "Wade Ward" <invalid@invalid.nyet>
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.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
0
Michele
7/6/2007 3:45:20 PM
On Fri, 06 Jul 2007 02:37:46 +0200, Gunnar Hjalmarsson
<noreply@gunnar.cc> 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:

Well, after all this does seem to be the case!


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
0
Michele
7/6/2007 3:52:51 PM
On Fri, 06 Jul 2007 11:18:35 +0200, Gunnar Hjalmarsson
<noreply@gunnar.cc> 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.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
0
Michele
7/6/2007 7:04:46 PM
Michele Dondi wrote:
> On Fri, 06 Jul 2007 02:37:46 +0200, Gunnar Hjalmarsson
> <noreply@gunnar.cc> 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
0
Gunnar
7/6/2007 7:24:37 PM
Michele Dondi wrote:
> On Fri, 06 Jul 2007 11:18:35 +0200, Gunnar Hjalmarsson
> <noreply@gunnar.cc> 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).

<snip>

> 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
0
Gunnar
7/6/2007 7:29:48 PM
"Michele Dondi" <bik.mido@tiscalinet.it> wrote in message 
news:8ros83hh9iopuqiejj0r1f2309lub7emt6@4ax.com...
> On Thu, 5 Jul 2007 17:25:51 -0400, "Wade Ward" <invalid@invalid.nyet>
> 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 


0
Wade
7/6/2007 7:30:01 PM
On Fri, 6 Jul 2007 15:30:01 -0400, "Wade Ward" <invalid@invalid.nyet>
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.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
0
Michele
7/6/2007 8:02:49 PM
On Fri, 06 Jul 2007 21:24:37 +0200, Gunnar Hjalmarsson
<noreply@gunnar.cc> 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:

:  if (@_ % 2) {
:    $host = shift ;
:    %arg  = @_;
:  } else {
:    %arg = @_;
:    $host=delete $arg{Host};
:  }


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
0
Michele
7/6/2007 8:04:23 PM
>>>>> "WW" == Wade Ward <invalid@invalid.nyet> writes:

  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
0
Uri
7/6/2007 8:05:48 PM
On Fri, 06 Jul 2007 22:02:49 +0200, Michele Dondi
<bik.mido@tiscalinet.it> 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.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
0
Michele
7/6/2007 8:31:10 PM
Michele Dondi <bik.mido@tiscalinet.it> writes:

> On Fri, 06 Jul 2007 22:02:49 +0200, Michele Dondi
> <bik.mido@tiscalinet.it> 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
0
Sherm
7/7/2007 1:03:41 AM
On Fri, 06 Jul 2007 21:03:41 -0400, Sherm Pendley
<spamtrap@dot-app.org> 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
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
0
Michele
7/7/2007 6:51:16 AM
"Michele Dondi" <bik.mido@tiscalinet.it> wrote in message 
news:5pdu839fptjcrc8171utccfbtrmbf4ms12@4ax.com...
> On Fri, 06 Jul 2007 21:03:41 -0400, Sherm Pendley
> <spamtrap@dot-app.org> 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... <grin>

P 

0
Peter
7/7/2007 8:56:28 AM
"Michele Dondi" <bik.mido@tiscalinet.it> wrote in message 
news:5pdu839fptjcrc8171utccfbtrmbf4ms12@4ax.com...
> On Fri, 06 Jul 2007 21:03:41 -0400, Sherm Pendley
> <spamtrap@dot-app.org> 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 


0
Wade
7/9/2007 5:31:56 PM
On Jul 6, 12:04 pm, Michele Dondi <bik.m...@tiscalinet.it> wrote:
> On Fri, 06 Jul 2007 11:18:35 +0200, Gunnar Hjalmarsson
>
> <nore...@gunnar.cc> 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

0
comp
7/9/2007 6:10:19 PM
On 9 Lug, 19:31, "Wade Ward" <inva...@invalid.nyet> 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

0
blazar
7/10/2007 1:17:10 PM
On 9 Lug, 20:10, "comp.llang.perl.moderated" <c...@blv-
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

0
blazar
7/10/2007 1:33:53 PM
On Thu, 05 Jul 2007 12:25:20 -0700 in comp.lang.perl.misc, Joe Smith
<joe@inwap.com> 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?
0
David
11/29/2007 7:03:22 AM
"David Harmon" <source@netcom.com> wrote in message 
news:13ksp20d0m9g2c5@corp.supernews.com...
> On Thu, 05 Jul 2007 12:25:20 -0700 in comp.lang.perl.misc, Joe Smith
> <joe@inwap.com> 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?
Dude, they're dissing you.

Your constructor fails.  They know why, and apparently, you don't.
-- 
Gerry Ford 




----== Posted via Newsgroups.com - Usenet Access to over 100,000 Newsgroups ==----
Get Anonymous, Uncensored, Access to West and East Coast Server Farms at! 
----== Highest Retention and Completion Rates! HTTP://WWW.NEWSGROUPS.COM ==----
0
Gerry
11/29/2007 11:11:21 AM
David Harmon <source@netcom.com> wrote:
> On Thu, 05 Jul 2007 12:25:20 -0700 in comp.lang.perl.misc, Joe Smith
><joe@inwap.com> 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/"
0
Tad
11/29/2007 12:16:22 PM
David Harmon <source@netcom.com> wrote in
news:13ksp20d0m9g2c5@corp.supernews.com: 

> On Thu, 05 Jul 2007 12:25:20 -0700 in comp.lang.perl.misc, Joe Smith
> <joe@inwap.com> 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@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
clpmisc guidelines: <URL:http://www.augustmail.com/~tadmc/clpmisc.shtml>

0
A
11/29/2007 12:18:42 PM
On Wed, 28 Nov 2007 23:03:22 -0800, David Harmon <source@netcom.com>
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:

Yes, the issue was resolved some months ago. How gentle of you to turn
it up again...

>sub new
>{
> my $self = shift;
> my $type = ref($self) || $self;
> my ($host,%arg);
> if (@_ % 2) {
>   $host = shift ;
>   %arg  = @_;
> } else {
>   %arg = @_;
>   $host=delete $arg{Host};
> }
[snip]
>The above looks wrong to me; I think it ought to be more like
>
> if (not (@_ % 2)) {

No, that's exactly what's intended. If you don't like what's intended,
then it's a wholly different problem. If you have a list with an odd
number of elements, then one is shifted off to be assigned to $host.
The remaining ones are interpreted as "named" parameters and put into
a hash. Otherwise, the parameters are assigned to a hash in the first
place.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
0
Michele
11/29/2007 10:32:24 PM
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.
0
David
11/30/2007 4:59:23 AM
On Thu, 29 Nov 2007 20:59:23 -0800, David Harmon <source@netcom.com>
wrote:

>>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

Somebody did figure it out.

>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

I gave a peek into the source as well. The documentation is clear
enough. Somebody just mistakenly assumed that the options should have
been passed as a hashref, which is not the case: some modules do that,
but there's no general rule. I'm really blessing 6's signatures now!

>of argument names and values; I think mentioning hash just confused
>the original poster.

Who incidentally *appears* to be confused enough in his own right...


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
0
Michele
11/30/2007 5:48:34 PM
Reply: