Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   Question about News::NNTPClient (http://www.velocityreviews.com/forums/t902007-question-about-news-nntpclient.html)

Fred 02-25-2007 06:43 PM

Question about News::NNTPClient
 
The script below lists ALL news groups for a particular news
server using the News::NNTPClient module. The list returned
looks similar to this with the group name, first article#,
last article#, and 'y' or 'n' if posting is allowed:

alt.test 0003911619 0003889349 y
alt.test-ns 0000006714 0000003335 y
alt.test.9 0000004684 0000002874 y
alt.test.a 0000057454 0000042977 y


The list is printed using "print $c->list()" (See below). I'm
trying to parse just the newsgroup name, so the list above
would look like:

alt.test
alt.test-ns
alt.test.9


I tried unsuccessfully using split like this:

my ($grpname, $first, $last, $postingallowed) = split(/ /, print
$c->list('active', 'alt.test*'));

print "$grpname\n";


I know I can parse the output and truncate 3 spaces to the right,
but is there a way to do this witrhin the script?

-Thanks



#!/usr/bin/perl -w

use strict;
use News::NNTPClient;


my $newshost = 'news.sprynet.com';
my $username = 'myaddy@comcast.net';
my $password = 'mypass';
my $port = '119';


# Connect to news server on port 119, debug level 1.
my $c = new News::NNTPClient($newshost, $port, 1);
unless ($nc->ok()) {
$nc->quit();
die $nc->message();
}


$c -> authinfo($username,$password);

print $c->list();

$c->quit();


Brian McCauley 02-25-2007 07:13 PM

Re: Question about News::NNTPClient
 
On Feb 25, 6:43 pm, Fred <itf...@cdw.com> wrote:
> Subject: Question about News::NNTPClient


Are you sure your question is about News::NNTPClient?

What makes you think that?

Don't fall into the trap of imagining that just because you happen to
be using News::NNTPClient at the time you encountered the question
does not mean it's a question about News::NNTPClient.

The only question you could be asking about News::NNTPClient is "what
does the list() method return" and that you either know or could
trivially look up.

Once you know the format how to parse it is not a question about
News::NNTPClient.

> The script below lists ALL news groups for a particular news
> server using the News::NNTPClient module. The list returned
> looks similar to this with the group name, first article#,
> last article#, and 'y' or 'n' if posting is allowed:
>
> alt.test 0003911619 0003889349 y
> alt.test-ns 0000006714 0000003335 y
> alt.test.9 0000004684 0000002874 y
> alt.test.a 0000057454 0000042977 y
>
> The list is printed using "print $c->list()" (See below).


Right, that _prints_ the list that is returned by the list() method.

> I'm
> trying to parse just the newsgroup name, so the list above
> would look like:
>
> alt.test
> alt.test-ns
> alt.test.9
>
> I tried unsuccessfully using split like this:
>
> my ($grpname, $first, $last, $postingallowed) = split(/ /, print
> $c->list('active', 'alt.test*'));


What to you think is the purpose of the print() in there?

Anyhow, there's one group name _per_line_ of the data returned by
list(). The above code is only trying to parse a single record. That's
gotta be wrong! You obviously need some sort of loop to perform some
action _for_each_line returned by list().

foreach( $c->list('active', 'alt.test*') ) {
my ($grpname, $first, $last, $postingallowed) = split;
# do whatever
}



All times are GMT. The time now is 07:51 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.