[32859] in Perl-Users-Digest
Perl-Users Digest, Issue: 4125 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jan 26 11:09:32 2014
Date: Sun, 26 Jan 2014 08:09:05 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sun, 26 Jan 2014 Volume: 11 Number: 4125
Today's topics:
Re: [OT] sys call length limitation <gamo@telecable.es>
Re: [OT] sys call length limitation (Tim McDaniel)
Re: [OT] sys call length limitation (Tim McDaniel)
Re: [OT] sys call length limitation <ben@morrow.me.uk>
Re: [OT] sys call length limitation <ben@morrow.me.uk>
Re: [OT] sys call length limitation (Tim McDaniel)
Re: [OT] sys call length limitation (Tim McDaniel)
Re: [OT] sys call length limitation <ben@morrow.me.uk>
Re: [OT] sys call length limitation <whynot@pozharski.name>
Re: [OT] sys call length limitation <rweikusat@mobileactivedefense.com>
Re: [OT] sys call length limitation <rweikusat@mobileactivedefense.com>
Re: [OT] sys call length limitation <rweikusat@mobileactivedefense.com>
Re: [OT] sys call length limitation <rweikusat@mobileactivedefense.com>
Re: [OT] sys call length limitation <rweikusat@mobileactivedefense.com>
creating a custom newsreader <cal@example.invalid>
Re: creating a custom newsreader <news@todbe.com>
Re: creating a custom newsreader <gamo@telecable.es>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 25 Jan 2014 21:06:22 +0100
From: gamo <gamo@telecable.es>
Subject: Re: [OT] sys call length limitation
Message-Id: <lc15g6$pmv$1@speranza.aioe.org>
El 25/01/14 01:59, * Tong * escribió:
> On Fri, 24 Jan 2014 13:35:34 +0000, Rainer Weikusat wrote:
>
>> Or consider using Perl. It's not that difficult:
>>
>> ---------------
>> sub filter {
>> {
>> my $fh = File::Temp->new();
>> print $fh (@_);
>> `wc -c < $fh`;
>> }
>> }
>> ---------------
>
> Thanks. that works really well, with that extra pair of braces that I
> didn't know what's for at the beginning.
>
Extra braces means scope, in particular to $fh.
Outside this scope, $fh is like if you type 'undef $fh;'
and since $fh is a file handle, this means that file
handle is closed.
You could replicate that without braces:
sub filter{
my $fh = File::Temp->new();
print $fh (@_);
my $ret = `wc -c $fh`;
undef $fh;
return $ret;
}
But it's a matter of economy, and style.
> Although being poked fun of doesn't feel good. But anyway,
>
> Thanks
>
--
http://www.telecable.es/personales/gamo/
------------------------------
Date: Sat, 25 Jan 2014 21:24:40 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: Re: [OT] sys call length limitation
Message-Id: <lc1a2o$1fe$1@reader1.panix.com>
In article <L%DEu.216375$Yb6.90559@fx29.iad>,
* Tong * <sun_tong_001@users.sourceforge.net> wrote:
>On Fri, 24 Jan 2014 13:35:34 +0000, Rainer Weikusat wrote:
>
>> Or consider using Perl. It's not that difficult:
>>
>> ---------------
>> sub filter {
>> {
>> my $fh = File::Temp->new();
>> print $fh (@_);
>> `wc -c < $fh`;
>> }
>> }
>> ---------------
>
>Thanks. that works really well, with that extra pair of braces that I
>didn't know what's for at the beginning.
Rainer did not provide those empty braces. What reason did you have
for adding them -- was there an error message, or different output, or
something? They shouldn't be needed for anything. The braces on sub
filter {...} delimit scope.
--
Tim McDaniel, tmcd@panix.com
------------------------------
Date: Sat, 25 Jan 2014 21:43:20 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: Re: [OT] sys call length limitation
Message-Id: <lc1b5o$rr9$1@reader1.panix.com>
In article <lc15g6$pmv$1@speranza.aioe.org>, gamo <gamo@telecable.es> wrote:
>El 25/01/14 01:59, * Tong * escribi_:
>> On Fri, 24 Jan 2014 13:35:34 +0000, Rainer Weikusat wrote:
>>
>>> Or consider using Perl. It's not that difficult:
>>>
>>> ---------------
>>> sub filter {
>>> {
>>> my $fh = File::Temp->new();
>>> print $fh (@_);
>>> `wc -c < $fh`;
>>> }
>>> }
Ooo, I just noticed what I think is a bug. $fh isn't flushed before
calling wc. I like to close files when done with them, but the
File::Temp man page says that some operating systems delete the file
on close, so we can't do that to flush it (or we can, if we want to
pass another argument to new() and handle the deletion ourselves,
which I don't).
I also prefer to do an explicit return statement. True, it's not
necessary in this sort of case. But I prefer it to make it clear that
I did intend to return at that spot (I won't absent-mindedly add code
after it and trash the return value) and I did intend that to be the
return value of the sub (that is, I didn't merely forget "return;" in
cases when I want the caller to get no return value).
File::Temp (on my machine's perl) says "The object isa 'IO::Handle'",
so this should work (though I've not tested it):
sub filter {
my $fh = File::Temp->new();
$fh->autoflush(1);
print $fh (@_);
return `wc -c < $fh`;
}
>>> ---------------
>>
>> Thanks. that works really well, with that extra pair of braces that
>> I didn't know what's for at the beginning.
>
>Extra braces means scope, in particular to $fh.
The braces in "sub filter {...}" delimit scope too. If the inner
braces weren't there, $fh would still go out of scope when the sub
returns.
>Outside this scope, $fh is like if you type 'undef $fh;'
You should always put "use strict;" at the top of each file. In that
case, going out of scope isn't "undef" -- it's a compile-time error.
Even without "use strict;", going out of scope isn't at all like
"undef". Outside its scope, $fh refers to an entirely different
variable. It might be undefined or it might not.
my $a = 3;
{
my $a = 25;
...
}
# here, the outer $a is back in scope and its value is 3.
>You could replicate that without braces:
>
>sub filter{
> my $fh = File::Temp->new();
> print $fh (@_);
> my $ret = `wc -c $fh`;
> undef $fh;
> return $ret;
>}
There's no need for the "undef $fh": as I noted above, it's going out
of scope anyway at the return, whether explicit or the implicit one
when it hits the close curly brace on a sub. I think my version above
should work.
--
Tim McDaniel, tmcd@panix.com
------------------------------
Date: Sat, 25 Jan 2014 22:28:23 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: [OT] sys call length limitation
Message-Id: <7dqdra-08p1.ln1@anubis.morrow.me.uk>
Quoth tmcd@panix.com:
> In article <L%DEu.216375$Yb6.90559@fx29.iad>,
> * Tong * <sun_tong_001@users.sourceforge.net> wrote:
> >On Fri, 24 Jan 2014 13:35:34 +0000, Rainer Weikusat wrote:
> >
> >> Or consider using Perl. It's not that difficult:
> >>
> >> ---------------
> >> sub filter {
> >> {
> >> my $fh = File::Temp->new();
> >> print $fh (@_);
> >> `wc -c < $fh`;
> >> }
> >> }
> >> ---------------
> >
> >Thanks. that works really well, with that extra pair of braces that I
> >didn't know what's for at the beginning.
>
> Rainer did not provide those empty braces.
Yes he did. Tong's newsreader appears to have messed up the threading,
but the message being replied to is
<87mwilpknt.fsf@sable.mobileactivedefense.com>, which has the extraneous
braces in.
Ben
------------------------------
Date: Sat, 25 Jan 2014 22:26:08 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: [OT] sys call length limitation
Message-Id: <09qdra-08p1.ln1@anubis.morrow.me.uk>
Quoth tmcd@panix.com:
> In article <lc15g6$pmv$1@speranza.aioe.org>, gamo <gamo@telecable.es> wrote:
> >El 25/01/14 01:59, * Tong * escribi_:
> >> On Fri, 24 Jan 2014 13:35:34 +0000, Rainer Weikusat wrote:
> >>
> >>> Or consider using Perl. It's not that difficult:
> >>>
> >>> ---------------
> >>> sub filter {
> >>> {
> >>> my $fh = File::Temp->new();
> >>> print $fh (@_);
> >>> `wc -c < $fh`;
> >>> }
> >>> }
>
> Ooo, I just noticed what I think is a bug. $fh isn't flushed before
> calling wc.
Yes. This is one of the things File::Slurp gets right, which is why I
was using it.
> File::Temp (on my machine's perl) says "The object isa 'IO::Handle'",
> so this should work (though I've not tested it):
>
> sub filter {
> my $fh = File::Temp->new();
> $fh->autoflush(1);
> print $fh (@_);
> return `wc -c < $fh`;
> }
This needs a
use IO::Handle;
unless something else has loaded it already (which you shouldn't rely
on). You can also just flush explicitly:
print ...;
$fh->flush;
Ben
------------------------------
Date: Sat, 25 Jan 2014 22:39:56 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: Re: [OT] sys call length limitation
Message-Id: <lc1efs$fpm$1@reader1.panix.com>
In article <09qdra-08p1.ln1@anubis.morrow.me.uk>,
Ben Morrow <ben@morrow.me.uk> wrote:
>
>Quoth tmcd@panix.com:
>> File::Temp (on my machine's perl) says "The object isa 'IO::Handle'",
>> so this should work (though I've not tested it):
>>
>> sub filter {
>> my $fh = File::Temp->new();
>> $fh->autoflush(1);
>> print $fh (@_);
>> return `wc -c < $fh`;
>> }
>
>This needs a
>
> use IO::Handle;
>
>unless something else has loaded it already (which you shouldn't rely
>on).
I'm not at all familiar with inheritance and haven't done much with
Perl OOP. Its statement that "The object isa 'IO::Handle'" isn't
sufficient? Is there a way that a module can be isa something else
without having its methods? The 5.14.2 version has
use base qw/ IO::Handle IO::Seekable /;
and "man base" indicates that that suffices.
Also, I can call Foo::Bar::Baz::Quux({ FROG => 'croak' }) without
"use Foo::Bar::Baz;" (though it's better style to do it). Why
doesn't $fh->Quuz(...) work -- isn't it blessed into File::Temp and
so shouldn't that isa-ing take care of it?
--
Tim McDaniel, tmcd@panix.com
------------------------------
Date: Sat, 25 Jan 2014 22:47:54 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: Re: [OT] sys call length limitation
Message-Id: <lc1euq$m0l$1@reader1.panix.com>
In article <7dqdra-08p1.ln1@anubis.morrow.me.uk>,
Ben Morrow <ben@morrow.me.uk> wrote:
>
>Quoth tmcd@panix.com:
>> In article <L%DEu.216375$Yb6.90559@fx29.iad>,
>> * Tong * <sun_tong_001@users.sourceforge.net> wrote:
>> >On Fri, 24 Jan 2014 13:35:34 +0000, Rainer Weikusat wrote:
>> >
>> >> Or consider using Perl. It's not that difficult:
>> >>
>> >> ---------------
>> >> sub filter {
>> >> {
>> >> my $fh = File::Temp->new();
>> >> print $fh (@_);
>> >> `wc -c < $fh`;
>> >> }
>> >> }
>> >> ---------------
>> >
>> >Thanks. that works really well, with that extra pair of braces that I
>> >didn't know what's for at the beginning.
>>
>> Rainer did not provide those empty braces.
>
>Yes he did. Tong's newsreader appears to have messed up the
>threading, but the message being replied to is
><87mwilpknt.fsf@sable.mobileactivedefense.com>, which has the
>extraneous braces in.
[rummage rummage]
Ah, I don't have that article. I have an article that includes header
lines
Message-ID: <87k3dppkjg.fsf@sable.mobileactivedefense.com>
Supersedes: <87mwilpknt.fsf@sable.mobileactivedefense.com>
So I suspect Rainer posted, realized "wait, I don't need the inner
braces" (maybe they were left over after some previous changes),
superceded the article ... and on my system the superceding was
actually obeyed.
--
Tim McDaniel, tmcd@panix.com
------------------------------
Date: Sat, 25 Jan 2014 23:41:38 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: [OT] sys call length limitation
Message-Id: <imudra-22q1.ln1@anubis.morrow.me.uk>
Quoth tmcd@panix.com:
> In article <09qdra-08p1.ln1@anubis.morrow.me.uk>,
> Ben Morrow <ben@morrow.me.uk> wrote:
> >
> >This needs a
> >
> > use IO::Handle;
> >
> >unless something else has loaded it already (which you shouldn't rely
> >on).
>
> I'm not at all familiar with inheritance and haven't done much with
> Perl OOP. Its statement that "The object isa 'IO::Handle'" isn't
> sufficient? Is there a way that a module can be isa something else
> without having its methods? The 5.14.2 version has
> use base qw/ IO::Handle IO::Seekable /;
> and "man base" indicates that that suffices.
Hmm. Yes, you may be right that File::Temp's documentation that it
inherits from IO::Handle allows you to assume that loading File::Temp
will load IO::Handle.
...in fact, I've just tested some things, and this is no longer a
problem in any case. I wonder when that changed?
It *used* to be the case that filehandles were blessed into (a subclass
of) IO::Handle by default, but the module was not loaded, so if you made
a method call on a filehandle without loading IO::Handle yourself you
got a 'method not found' error. However, I've just tested this:
perl -le'STDIN->flush; print for keys %INC'
and it seems that with recent versions of perl calling a method on a
filehandle will autoload IO::Handle for you. So that's OK...
> Also, I can call Foo::Bar::Baz::Quux({ FROG => 'croak' }) without
> "use Foo::Bar::Baz;" (though it's better style to do it).
Only if something else has defined that function, or loaded the module.
Otherwise you get an 'undefined subroutine' error at runtime.
> Why
> doesn't $fh->Quuz(...) work -- isn't it blessed into File::Temp and
> so shouldn't that isa-ing take care of it?
Method calls work exactly like function calls in this respect: at
runtime, when the call is made, the method needs to exist (or be
autoloadable) or you get an error.
What used to happen with filehandles was the equivalent of
bless *STDOUT{IO}, "IO::File";
without loading IO/File.pm or IO/Handle.pm. (This then causes method
calls like STDOUT->flush to be looked up in IO::File, because that's one
of the strategies Perl tries when resolving a method call on a
bareword.) If you try this with a more ordinary object
my $x = bless {}, "Foo";
$x->foo;
# or simply
Foo->foo;
you will get a 'can't locate object method' error.
It seems that the special case here is only for IO::File, which is in
fact the class filehandles are blessed into by default. If you rebless a
handle into some other class the autoloading doesn't happen:
~% perl -e'bless *STDOUT{IO}, "IO::Handle"; STDOUT->flush'
Can't locate object method "flush" via package "IO::Handle" at -e
line 1.
~% perl -e'bless *STDOUT{IO}, "File::Temp";
@File::Temp::ISA = qw/IO::Handle IO::Seekable/;
STDOUT->flush'
Can't locate object method "flush" via package "File::Temp" at -e
line 1.
Ben
------------------------------
Date: Sun, 26 Jan 2014 12:26:20 +0200
From: Eric Pozharski <whynot@pozharski.name>
Subject: Re: [OT] sys call length limitation
Message-Id: <slrnle9omc.n03.whynot@orphan.zombinet>
with <imudra-22q1.ln1@anubis.morrow.me.uk> Ben Morrow wrote:
*SKIP*
> ...in fact, I've just tested some things, and this is no longer a
> problem in any case. I wonder when that changed?
5.11.3
*CUT*
--
Torvalds' goal for Linux is very simple: World Domination
Stallman's goal for GNU is even simpler: Freedom
------------------------------
Date: Sun, 26 Jan 2014 14:33:14 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: [OT] sys call length limitation
Message-Id: <87mwiike39.fsf@sable.mobileactivedefense.com>
tmcd@panix.com (Tim McDaniel) writes:
> In article <lc15g6$pmv$1@speranza.aioe.org>, gamo <gamo@telecable.es> wrote:
>>El 25/01/14 01:59, * Tong * escribi_:
>>> On Fri, 24 Jan 2014 13:35:34 +0000, Rainer Weikusat wrote:
>>>
>>>> Or consider using Perl. It's not that difficult:
>>>>
>>>> ---------------
>>>> sub filter {
>>>> {
>>>> my $fh = File::Temp->new();
>>>> print $fh (@_);
>>>> `wc -c < $fh`;
>>>> }
>>>> }
>
> Ooo, I just noticed what I think is a bug. $fh isn't flushed before
> calling wc.
Except when I explicitly say so, I don't post code which hasn't been
tested and it is being flushed on the system/ with the perl version I
was using. Which is the behaviour I expected considering that
Beginning with v5.6.0, Perl will attempt to flush all files
opened for output before forking the child process, but this may
not be supported on some platforms (see perlport).
(perldoc -f fork)
According to perlport (5.10.1 - 5.18.0) fork
Does not automatically flush output handles on some platforms.
(SunOS, Solaris, HP-UX)
If this was of concern, the obvious alternative would be
syswrite($fh, $_) for @_;
But I generally don't care if "something doesn't work on Solaris"
(especially not if it is related to fork which only "works on Solaris"
for a very peculiar definition of "working", anyway ...).
> I also prefer to do an explicit return statement. True, it's not
> necessary in this sort of case.
Me too. But since this was (necessarily) partially on exercise in "text
reduction", I omitted it here.
------------------------------
Date: Sun, 26 Jan 2014 14:36:11 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: [OT] sys call length limitation
Message-Id: <87iot6kdyc.fsf@sable.mobileactivedefense.com>
gamo <gamo@telecable.es> writes:
>> On Fri, 24 Jan 2014 13:35:34 +0000, Rainer Weikusat wrote:
>>
>>> Or consider using Perl. It's not that difficult:
>>>
>>> ---------------
>>> sub filter {
>>> {
>>> my $fh = File::Temp->new();
>>> print $fh (@_);
>>> `wc -c < $fh`;
>>> }
>>> }
>>> ---------------
>>
>> Thanks. that works really well, with that extra pair of braces that I
>> didn't know what's for at the beginning.
>>
>
> Extra braces means scope, in particular to $fh.
> Outside this scope, $fh is like if you type 'undef $fh;'
> and since $fh is a file handle, this means that file
> handle is closed.
>
> You could replicate that without braces:
>
> sub filter{
> my $fh = File::Temp->new();
> print $fh (@_);
> my $ret = `wc -c $fh`;
> undef $fh;
> return $ret;
> }
>
> But it's a matter of economy, and style.
The inner block was left-over from a previous version and was supposed
to force $fh to go out of scope and hence, being flushed and closed,
before executing the command because I originally thought this was
necessary. When I noticed this, I did a supersede of the original
article with the superfluous {} removed but "some servers" (in
particular, the Google-servers) don't honour any "author control of
erronously published text" commands.
------------------------------
Date: Sun, 26 Jan 2014 14:44:37 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: [OT] sys call length limitation
Message-Id: <87bnyykdka.fsf@sable.mobileactivedefense.com>
Ben Morrow <ben@morrow.me.uk> writes:
> Quoth tmcd@panix.com:
>> In article <09qdra-08p1.ln1@anubis.morrow.me.uk>,
>> Ben Morrow <ben@morrow.me.uk> wrote:
>> >
>> >This needs a
>> >
>> > use IO::Handle;
>> >
>> >unless something else has loaded it already (which you shouldn't rely
>> >on).
>>
>> I'm not at all familiar with inheritance and haven't done much with
>> Perl OOP. Its statement that "The object isa 'IO::Handle'" isn't
>> sufficient? Is there a way that a module can be isa something else
>> without having its methods? The 5.14.2 version has
>> use base qw/ IO::Handle IO::Seekable /;
>> and "man base" indicates that that suffices.
>
> Hmm. Yes, you may be right that File::Temp's documentation that it
> inherits from IO::Handle allows you to assume that loading File::Temp
> will load IO::Handle.
The relevant text is actually 'The object isa "IO::Handle" and isa "IO::Seekable"
so all those methods are available'. Consequently, if those methods
weren't available, this would be a bug in File::Temp.
------------------------------
Date: Sun, 26 Jan 2014 14:56:56 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: [OT] sys call length limitation
Message-Id: <877g9mkczr.fsf@sable.mobileactivedefense.com>
Ben Morrow <ben@morrow.me.uk> writes:
> Quoth tmcd@panix.com:
>> In article <lc15g6$pmv$1@speranza.aioe.org>, gamo <gamo@telecable.es> wrote:
>> >El 25/01/14 01:59, * Tong * escribi_:
>> >> On Fri, 24 Jan 2014 13:35:34 +0000, Rainer Weikusat wrote:
>> >>
>> >>> Or consider using Perl. It's not that difficult:
>> >>>
>> >>> ---------------
>> >>> sub filter {
>> >>> {
>> >>> my $fh = File::Temp->new();
>> >>> print $fh (@_);
>> >>> `wc -c < $fh`;
>> >>> }
>> >>> }
>>
>> Ooo, I just noticed what I think is a bug. $fh isn't flushed before
>> calling wc.
>
> Yes. This is one of the things File::Slurp gets right, which is why I
> was using it.
It is actually perl which "gets this right", at least for the given
case.
------------------------------
Date: Sun, 26 Jan 2014 15:02:16 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: [OT] sys call length limitation
Message-Id: <8738kakcqv.fsf@sable.mobileactivedefense.com>
* Tong * <sun_tong_001@users.sourceforge.net> writes:
> On Fri, 24 Jan 2014 13:35:34 +0000, Rainer Weikusat wrote:
>
>> Or consider using Perl. It's not that difficult:
>>
>> ---------------
>> sub filter {
>> {
>> my $fh = File::Temp->new();
>> print $fh (@_);
>> `wc -c < $fh`;
>> }
>> }
>> ---------------
>
> Thanks. that works really well, with that extra pair of braces that I
> didn't know what's for at the beginning.
>
> Although being poked fun of doesn't feel good. But anyway,
The way you were assigning "ex cathedra" grades to different postings
didn't feel very good, either[*].
[*] Assuming that life's a competition, who wins? The guy who dies first
or the guy who dies last?
------------------------------
Date: Sun, 26 Jan 2014 00:57:13 -0800
From: Cal Dershowitz <cal@example.invalid>
Subject: creating a custom newsreader
Message-Id: <AJWdnWigUPxVLHnPnZ2dnUVZ_vKdnZ2d@supernews.com>
Howdy newsgroup,
I'm a little bit bored and have decided to indulge a hobby project. I
have one binary group that I download: alt.binaries.humor.skewed, and it
has been a great group over the years, but recently is beset by so much
nauseating racism, that I can't look at it anymore. If I didn't go out
of my way to disavow it tonight, the arbitrary advanced observer might
notice these unwanted images coming to my machine and think that I have
some sympathy for them.
So it is that I will either write an effective way to avoid these
images, or I'll scale back to NIN and avoid the world of usenet binaries
altogether. I figure they're not more clever than a well-written regex.
So I've started this great thing, downloaded News::NNTPClient, man'ed it
a couple times, and I thought I would find a means of authentication in
there that would be the analog of ftp'ing, but I haven't:
$ perl nntp2.pl
News::NNTPClient: Bad hostname: news at nntp2.pl line 8.
Can't locate object method "comp.lang.perl.misc" via package
"News::NNTPClient" at nntp2.pl line 10.
$ cat nntp2.pl
#!/usr/bin/perl -w
use strict;
use 5.010;
use lib "template_stuff";
use nntp1;
use News::NNTPClient;
my $c = new News::NNTPClient;
my $group1 = "comp.lang.perl.misc";
my ($first,$last) = $c->$group1;
say $first;
say $last;
$ cd template_stuff/
$ cat nntp1.pm
#!/usr/bin/perl -w
package nntp1;
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw( get_ftp_object);
our %config = (
my_ftp => {
domain => '',
username => '',
password => '',
},
usenet => {
domain => '',
username => '',
password => '',
},
);
sub get_ftp_object{
use strict;
use Net::FTP;
my $sub_hash = "my_ftp";
my $domain = $config{$sub_hash}->{'domain'};
my $username = $config{$sub_hash}->{'username'};
my $password = $config{$sub_hash}->{'password'};
#dial up the server
my $ftp = Net::FTP->new( $domain, Debug => 1, Passive => 1 )
or die "Can't connect: $!\n";
$ftp->login( $username, $password)
or die "Couldn't login\n";
return $ftp;
}
$
On my machine, the values in %config are all populated, so I thought I
would just re-write get_ftp_object with a get_nntp_object , but I don't
see the equivalent of a login method.
Thanks for your comment, and cheers from the great state of california.
--
Cal Dershowitz
------------------------------
Date: Sun, 26 Jan 2014 00:06:49 -0800
From: "$Bill" <news@todbe.com>
Subject: Re: creating a custom newsreader
Message-Id: <lc2fmm$eur$1@dont-email.me>
On 1/26/2014 00:57, Cal Dershowitz wrote:
> Howdy newsgroup,
>
> I'm a little bit bored and have decided to indulge a hobby project. I have one binary group that I download: alt.binaries.humor.skewed, and it has been a great group over the years, but recently is beset by so much nauseating racism, that I can't look at it anymore. If I didn't go out of my way to disavow it tonight, the arbitrary advanced observer might notice these unwanted images coming to my machine and think that I have some sympathy for them.
>
> So it is that I will either write an effective way to avoid these images, or I'll scale back to NIN and avoid the world of usenet binaries altogether. I figure they're not more clever than a well-written regex.
>
> So I've started this great thing, downloaded News::NNTPClient, man'ed it a couple times, and I thought I would find a means of authentication in there that would be the analog of ftp'ing, but I haven't:
<code here>
> On my machine, the values in %config are all populated, so I thought I would just re-write get_ftp_object with a get_nntp_object , but I don't see the equivalent of a login method.
>
> Thanks for your comment, and cheers from the great state of california.
I stripped some code out of a working script that should help you -
just fill in the host/user/pass/ip fields and maybe change the loop
index to something other than 10:
#!perl --
use strict;
use warnings;
use Net::NNTP;
my $group = 'alt.test'; # newsgroup
my $host = ''; # server hostname
my $user = ''; # username - null skips authorization
my $pass = ''; # password
my $ip = ''; # IP addr - I use this just in case DNS is down
# create news server connection
print "New NNTP connection to $host\n";
my $nntp;
if (not $nntp = Net::NNTP->new($host, Timeout => 15)) {
warn "Cannot connect to $host: $! ($^E)";
if (not $nntp = Net::NNTP->new($ip, Timeout => 15)) {
die "Cannot connect to $ip: $! ($^E)";
}
}
# login
print "sending auth\n";
$nntp->authinfo ($user, $pass) or die "nntp->authinfo: $! ($^E)" if $user;
# set newsgroup
print "Setting group\n";
my ($cnt, $first, $last, $grp) = $nntp->group($group) or
die "group failed: $! ($^E)";
print "cnt=$cnt, first=$first, last=$last, grp=$grp\n";
# start at last message
my $msgnum = $last;
for (my $ii = 0; $ii < 10; $ii++) {
# get msg header
print "get $msgnum head\n";
my $head = $nntp->head($msgnum) or do {
warn "nntp->head $msgnum failed: $! ($^E)";
goto next_msg; # skip message - you could retry
};
print "head has ", scalar @$head, " lines\n";
# filter msg based on header
# ... <your code here>
# get msg body
print "get $msgnum body\n";
my $bodyref = $nntp->body($msgnum) or do {
die "nntp->body $msgnum failed: $!\n";
next;
};
print "body has ", scalar @$bodyref, " lines\n";
next_msg:
# go to prior message
my $msgid;
unless ($msgid = $nntp->last()) {
print "nntp->last($ii): $!\n";
last;
}
print "last: $msgid\n";
# get msg number for header request
$msgnum = $nntp->message();
chomp $msgnum;
print "message: $msgnum\n";
$msgnum =~ s/^\s*(\d+)\s+.*$/$1/;
}
$nntp->quit;
__END__
------------------------------
Date: Sun, 26 Jan 2014 10:08:47 +0100
From: gamo <gamo@telecable.es>
Subject: Re: creating a custom newsreader
Message-Id: <lc2jb9$sfl$1@speranza.aioe.org>
El 26/01/14 09:57, Cal Dershowitz escribió:
> Howdy newsgroup,
>
> I'm a little bit bored and have decided to indulge a hobby project. I
But a hobby doesn't means you doesn't RTFM.
You basically failed to provide a server, and a group.
Try something around this:
#!/usr/bin/perl -w
use News::NNTPClient;
$c = new News::NNTPClient("news.aioe.org");
($first, $last) = ($c->group("comp.lang.perl.misc"));
for (; $first <= $last; $first++) {
print $c->article($first);
}
__END__
This will print a lot of articles. That module provides _examples_
as how to get articles i.e. by time.
> Thanks for your comment, and cheers from the great state of california.
Cheers from hell
--
http://www.telecable.es/personales/gamo/
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 4125
***************************************