Question about News::NNTPClient

Discussion in 'Perl Misc' started by Fred, Feb 25, 2007.

  1. Fred

    Fred Guest

    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 = '';
    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();
    Fred, Feb 25, 2007
    #1
    1. Advertising

  2. On Feb 25, 6:43 pm, Fred <> 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
    }
    Brian McCauley, Feb 25, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gurdeep Saini

    NNTPClient Question

    Gurdeep Saini, Nov 11, 2004, in forum: Perl
    Replies:
    1
    Views:
    525
    Anthony Papillion II
    Nov 12, 2004
  2. Paul Briggs
    Replies:
    1
    Views:
    405
    Mitja
    Jun 8, 2004
  3. Talimore
    Replies:
    4
    Views:
    541
    T. Audry Glamour
    Jul 18, 2004
  4. Amy
    Replies:
    0
    Views:
    504
  5. Jason (Kusanagihk)
    Replies:
    1
    Views:
    451
    Ian Shef
    Oct 1, 2008
Loading...

Share This Page