Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

How to print an entire nntp article

by mpj196884 (Novice)
on May 23, 2009 at 02:55 UTC ( [id://765786]=perlquestion: print w/replies, xml ) Need Help??

mpj196884 has asked for the wisdom of the Perl Monks concerning the following question:

I'm looking for some pointers on how to print the entire nntp article. I've only been studying perl for coming up on two years now.
#!/usr/bin/perl # perl qq2.pl ##minimal nntp client use strict; use warnings; use Net::NNTP (); use constant NUMBER_OF_ARTICLES => 2; use constant GROUP_NAME => 'comp.lang.perl.misc'; 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 = 'merrilljensen'; my $PASS = 'quoatohngipu'; $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 R +ETRIEVE; # 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; } print $nntp->body; __END__
output:
C:\MinGW\source>perl qq2.pl ARRAY(0x1a16d80)ARRAY(0x1a16c3c) C:\MinGW\source>perl qq2.pl ARRAY(0x1a16b1c) C:\MinGW\source>
Thanks for your comment and cheers,

Replies are listed 'Best First'.
Re: How to print an entire nntp article
by Anonymous Monk on May 23, 2009 at 07:13 UTC
    use Data::Dumper; print Dumper( $nntp, $nntp->body ); __END__
Re: How to print an entire nntp article
by mpj196884 (Novice) on May 23, 2009 at 03:04 UTC
    sorry I forgot to redact my $pass $it's different now I like to think of the computers that work where i use to ride the sidewalk, as Berlin's large, jelly-filled donut.
Re: How to print an entire nntp article
by saberworks (Curate) on May 26, 2009 at 03:28 UTC
    Documentation says...
    If FH is not specified then the return value, on success, will be a reference to an array containing the article requested, each entry in the array will contain one line of the article.
    I've used this module before and it seems like it returned a real array from the body() method, so I'm guessing you can do:

    print "$_\n" for $article->body();

    But if it's returning an arrayref, just dereference it:

    print "$_\n" for @{$article->body()};

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://765786]
Front-paged by tye
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2024-04-25 16:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found