G
George
I would like to extend the following script:
#!/usr/bin/perl -w
use strict;
use Net::NNTP ();
use constant NUMBER_OF_ARTICLES => 10;
use constant GROUP_NAME => 'alt.solaris.x86';
use constant SERVER_NAME => 'news.individual.net';
use constant NNTP_DEBUG => 0;
my $nntp = Net::NNTP->new(SERVER_NAME, 'Debug' => NNTP_DEBUG) or die;
my $USER = '';
my $PASS = '';
$nntp->authinfo($USER,$PASS) or die $!;
my($article_count, $first_article, $last_article) =
$nntp->group(GROUP_NAME) or die;
# Which XOVER fields contain Subject: and From:?
my $count = 0;
my %xover_fmt = map( ($_, $count++), @{ $nntp->overview_fmt or die} );
die unless exists $xover_fmt{'Subject:'};
my $subject_offset = $xover_fmt{'Subject:'};
my $from_offset = $xover_fmt{'From:'};
my(@xover, $start_article);
RETRIEVE: while ($#xover+1 < NUMBER_OF_ARTICLES and $last_article >=
$first_article) {
# How many articles do we need? Stop retrieving if we have enough
my $articles_required = NUMBER_OF_ARTICLES - ($#xover+1) or last
RETRIEVE;
# Fetch overview information for the articles
$start_article = $last_article - ($articles_required-1);
$start_article = $start_article > $first_article ? $start_article :
$first_article;
my $xover_query = $start_article == $last_article ?
$start_article :
[$start_article, $last_article];
my $xover_ref = $nntp->xover($xover_query) or die;
# Store headers for the articles we've retrieved
foreach (sort {$b <=> $a} keys %$xover_ref) {
push @xover, $xover_ref->{$_};
}
} continue {
# Move the pointer forward to fetch previous articles
$last_article = $start_article - 1;
}
# Disconnect from the NNTP server
$nntp->quit;
print join("\n", map ($_->[$subject_offset].' from '.$_->[$from_offset],
@xover)),"\n";
# perl script1.pl 2>text50.txt >text51.txt
Current output is:
C:\MinGW\source>perl script1.pl
Re: Solaris 10 update 6 on Intel x86. from CJT <[email protected]>
Re: Solaris 10 update 6 on Intel x86. from Ian Collins
<[email protected]>
Re: Solaris 10 update 6 on Intel x86. from Atiqur Rahman <[email protected]>
Re: Solaris 10 update 6 on Intel x86. from Ian Collins
<[email protected]>
Re: Solaris 10 update 6 on Intel x86. from Atiqur Rahman <[email protected]>
Re: Solaris 10 update 6 on Intel x86. from Atiqur Rahman <[email protected]>
Re: Solaris 10 update 6 on Intel x86. from Atiqur Rahman <[email protected]>
Re: Solaris 10 update 6 on Intel x86. from (e-mail address removed)
Solaris 10 update 6 on Intel x86. from Atiqur Rahman <[email protected]>
Re: Booting multi-user but w/o X from (e-mail address removed)
C:\MinGW\source>
The way I would like to extend this is the following:
If the article is from 'Atiqur Rahman', then I would like to print the
entire article.
This may sound trivially easy to those with more experience with perl. I
find the control structures very difficult in perl. I've done similar
things before, but it's been a while since I've used perl. I have
_Programming Perl_ as a reference.
Thanks for your comment.
--
George
We will stand up for our friends in the world. And one of the most
important friends is the State of Israel. My administration will be
steadfast in support Israel against terrorism and violence, and in seeking
the peace for which all Israelis pray.
George W. Bush
Picture of the Day http://apod.nasa.gov/apod/
#!/usr/bin/perl -w
use strict;
use Net::NNTP ();
use constant NUMBER_OF_ARTICLES => 10;
use constant GROUP_NAME => 'alt.solaris.x86';
use constant SERVER_NAME => 'news.individual.net';
use constant NNTP_DEBUG => 0;
my $nntp = Net::NNTP->new(SERVER_NAME, 'Debug' => NNTP_DEBUG) or die;
my $USER = '';
my $PASS = '';
$nntp->authinfo($USER,$PASS) or die $!;
my($article_count, $first_article, $last_article) =
$nntp->group(GROUP_NAME) or die;
# Which XOVER fields contain Subject: and From:?
my $count = 0;
my %xover_fmt = map( ($_, $count++), @{ $nntp->overview_fmt or die} );
die unless exists $xover_fmt{'Subject:'};
my $subject_offset = $xover_fmt{'Subject:'};
my $from_offset = $xover_fmt{'From:'};
my(@xover, $start_article);
RETRIEVE: while ($#xover+1 < NUMBER_OF_ARTICLES and $last_article >=
$first_article) {
# How many articles do we need? Stop retrieving if we have enough
my $articles_required = NUMBER_OF_ARTICLES - ($#xover+1) or last
RETRIEVE;
# Fetch overview information for the articles
$start_article = $last_article - ($articles_required-1);
$start_article = $start_article > $first_article ? $start_article :
$first_article;
my $xover_query = $start_article == $last_article ?
$start_article :
[$start_article, $last_article];
my $xover_ref = $nntp->xover($xover_query) or die;
# Store headers for the articles we've retrieved
foreach (sort {$b <=> $a} keys %$xover_ref) {
push @xover, $xover_ref->{$_};
}
} continue {
# Move the pointer forward to fetch previous articles
$last_article = $start_article - 1;
}
# Disconnect from the NNTP server
$nntp->quit;
print join("\n", map ($_->[$subject_offset].' from '.$_->[$from_offset],
@xover)),"\n";
# perl script1.pl 2>text50.txt >text51.txt
Current output is:
C:\MinGW\source>perl script1.pl
Re: Solaris 10 update 6 on Intel x86. from CJT <[email protected]>
Re: Solaris 10 update 6 on Intel x86. from Ian Collins
<[email protected]>
Re: Solaris 10 update 6 on Intel x86. from Atiqur Rahman <[email protected]>
Re: Solaris 10 update 6 on Intel x86. from Ian Collins
<[email protected]>
Re: Solaris 10 update 6 on Intel x86. from Atiqur Rahman <[email protected]>
Re: Solaris 10 update 6 on Intel x86. from Atiqur Rahman <[email protected]>
Re: Solaris 10 update 6 on Intel x86. from Atiqur Rahman <[email protected]>
Re: Solaris 10 update 6 on Intel x86. from (e-mail address removed)
Solaris 10 update 6 on Intel x86. from Atiqur Rahman <[email protected]>
Re: Booting multi-user but w/o X from (e-mail address removed)
C:\MinGW\source>
The way I would like to extend this is the following:
If the article is from 'Atiqur Rahman', then I would like to print the
entire article.
This may sound trivially easy to those with more experience with perl. I
find the control structures very difficult in perl. I've done similar
things before, but it's been a while since I've used perl. I have
_Programming Perl_ as a reference.
Thanks for your comment.
--
George
We will stand up for our friends in the world. And one of the most
important friends is the State of Israel. My administration will be
steadfast in support Israel against terrorism and violence, and in seeking
the peace for which all Israelis pray.
George W. Bush
Picture of the Day http://apod.nasa.gov/apod/