Question about News::NNTPClient

F

Fred

The script below lists ALL news groups for a particular news
server using the 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

my $newshost = 'news.sprynet.com';
my $username = '(e-mail address removed)';
my $password = 'mypass';
my $port = '119';


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


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

print $c->list();

$c->quit();
 
B

Brian McCauley

Subject: Question about News::NNTPClient

Are you sure your question is about
What makes you think that?

Don't fall into the trap of imagining that just because you happen to
be using at the time you encountered the question
does not mean it's a question about
The only question you could be asking about 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
The script below lists ALL news groups for a particular news
server using the 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
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top