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

I want to save an entire nntp article in a flat file i.e copy its entire contents and print them in a local file. I considered using the article() function and the tied file handle it returns. But I am not able to use it properly. Otherwise, I am able to use other functions of the NNTP module such as list() and group() correctly. However, I am facing issues with article() and articlefh(). Can anyone help?

$nntp->article($last,<FH>);

Replies are listed 'Best First'.
Re: how to use article() function in perl Net::NNTP module?
by Corion (Patriarch) on Oct 21, 2013 at 10:06 UTC

    You don't show us what kind of problems you have, so it is hard to suggest how to proceed.

    Have you looked at the demos included with Net::NNTP, especially the nntp sample? Maybe you just want to do the same, except save things into a file?

    The following gives you information about the kind of data structure returned by ->article. Handling that data structure is likely best done through References Quick Reference.

    ... use Data::Dumper print Dumper $nntp->article( $last ); ...

      Thanks for the references.Those would definitely help at some point or other. Now, I am able to do the required task with the following code

      open(ARTICLE,">>indexer.txt") or die "Cannot open indexer.txt"; my $data=$nntp->article(99); print ARTICLE @$data; #print ARTICLE "Completed Successfully"; close(ARTICLE);
      However, I want to know if there is a better way to do it using the file handle that the article() function returns. As for data dumper, it does the task as well, but the output is in pretty untidy format. And the problem I am facing is that I do not know how to use tied filehandles. Any code snippet would be highly appreciated

        You can treat a (tied) filehandle just like any other filehandle. It acts like a filehandle, but maybe its data does reside in memory or somewhere else. As a consumer of data, you usually don't need to care about this.

        ... my $fh= $nntp->articlefh(...); while( <$fh>) { print "Article: $_\n"; }; ...
Re: how to use article() function in perl Net::NNTP module?
by Anonymous Monk on Oct 21, 2013 at 19:14 UTC
    The syntax it is expecting (I think) is:
    open($article, ">>", indexer.txt") or die $!; $nntp->article($last, $article);
    Note the use of a scalar file handle ($fh instead of FH). Also note the few modernisations I gave your code.

    Your syntax (<FH>) would use the <> operator to try to read from the file handle and pass the result as an argument, rather than pass the actual file handle.