printing a subject line - Perl

This is a discussion on printing a subject line - Perl ; #!/usr/bin/perl use strict; use Net::NNTP (); use constant NUMBER_OF_ARTICLES => 1; use constant GROUP_NAME => 'comp.lang.perl.misc'; use constant SERVER_NAME => 'newsgroups.comcast.net'; use constant NNTP_DEBUG => 0; my $nntp = Net::NNTP->new(SERVER_NAME, 'Debug' => NNTP_DEBUG) or die; my $USER = ''; my ...

+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 17

printing a subject line

  1. Default printing a subject line

    #!/usr/bin/perl

    use strict;
    use Net::NNTP ();

    use constant NUMBER_OF_ARTICLES => 1;
    use constant GROUP_NAME => 'comp.lang.perl.misc';
    use constant SERVER_NAME => 'newsgroups.comcast.net';
    use constant NNTP_DEBUG => 0;

    my $nntp = Net::NNTP->new(SERVER_NAME, 'Debug' => NNTP_DEBUG) or die;
    my $USER = '';
    my $PASS = '';

    $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

    RETRIEVE;


    # 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;
    }

    # Disconnect from the NNTP server
    $nntp->quit;
    # trouble is between here and the end
    my $string1 = $_->[$subject_offset];

    print join("\n", map ($_->[$subject_offset].' from

    '.$_->[$from_offset], @xover)),"\n";
    print $string1 ;
    #end script begin comment
    This script has tested ok on its ability to grab a usenet message. Now I
    want to do soemthing with the subject, and I don't see where I go wrong. I
    think I get the subject into my $string with:
    my $string1 = $_->[$subject_offset];
    Perl.exe says $string1 is unitialized in the ultimate print statement. What
    gives?
    --
    wade ward
    "Nicht verzagen, Bruder Grinde fragen."



  2. Default Re: printing a subject line

    >>>>> "WW" == Wade Ward <zaxfuuq@invalid.net> writes:

    WW> This script has tested ok on its ability to grab a usenet
    WW> message. Now I want to do soemthing with the subject, and I
    WW> don't see where I go wrong. I think I get the subject into my
    WW> $string with: my $string1 = $_->[$subject_offset]; Perl.exe
    WW> says $string1 is unitialized in the ultimate print statement.
    WW> What gives?

    I recommend running it under the debugger to find out. In particular,
    you will be able to determine precisely whether you get the subject
    into $string1 (which probably ought to be called, you know, $subject).

    perldoc perldebtut

    And consider use warnings; as well -- you're probably doing some
    warnings-appropriate things there, but I'm not going to go through the
    code to point them out when perl can do it automatically.

    Charlton





    --
    Charlton Wilbur
    cwilbur@chromatico.net

  3. Default Re: printing a subject line

    >>>>> "WW" == Wade Ward <zaxfuuq@invalid.net> writes:

    WW> Thanks for your reply and what a fantastic tool! That
    WW> tutorial brought me about 75% there on this problem. With the
    WW> script as: [snip]
    WW> , how do I use the debugger to see the value of $subject?

    My pager indicates that the section of perldoc perldebtut that covers
    the use of the debugger is approximately 20% into the document.

    Charlton





    --
    Charlton Wilbur
    cwilbur@chromatico.net

  4. Default Re: printing a subject line



    "Charlton Wilbur" <cwilbur@chromatico.net> wrote in message
    news:87tzopkdte.fsf@mithril.chromatico.net...
    >>>>>> "WW" == Wade Ward <zaxfuuq@invalid.net> writes:

    >
    > WW> This script has tested ok on its ability to grab a usenet
    > WW> message. Now I want to do soemthing with the subject, and I
    > WW> don't see where I go wrong. I think I get the subject into my
    > WW> $string with: my $string1 = $_->[$subject_offset]; Perl.exe
    > WW> says $string1 is unitialized in the ultimate print statement.
    > WW> What gives?
    >
    > I recommend running it under the debugger to find out. In particular,
    > you will be able to determine precisely whether you get the subject
    > into $string1 (which probably ought to be called, you know, $subject).

    Thanks for your reply and what a fantastic tool! That tutorial brought me
    about 75% there on this problem. With the script as:
    #!/usr/bin/perl

    use strict;
    use warnings;
    use Net::NNTP ();

    use constant NUMBER_OF_ARTICLES => 1;
    use constant GROUP_NAME => 'comp.lang.perl.misc';
    use constant SERVER_NAME => 'newsgroups.comcast.net';
    use constant NNTP_DEBUG => 0;

    my $nntp = Net::NNTP->new(SERVER_NAME, 'Debug' => NNTP_DEBUG) or die;
    my $USER = '';
    my $PASS = '';

    $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
    RETRIEVE;


    # 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;
    }

    # Disconnect from the NNTP server
    $nntp->quit;

    my $subject = $_->[$subject_offset];

    print join("\n", map ($_->[$subject_offset].' from '.$_->[$from_offset],
    @xover)),"\n";
    print $subject ;
    __END__

    , how do I use the debugger to see the value of $subject?
    http://www.zaxfuuq.net/perl10.htm
    --
    wade ward
    "Nicht verzagen, Bruder Grinde fragen."



  5. Default Re: printing a subject line

    On Wed, 17 Oct 2007 15:01:24 -0700, "Wade Ward" <zaxfuuq@invalid.net>
    wrote:

    ># Disconnect from the NNTP server
    >$nntp->quit;
    >
    >my $subject = $_->[$subject_offset];


    Due to severe lack of time, I didn't read the whole code, but that
    looks suspiscious: what is $_ at that point?!? Why should it contain
    an arrayref? Suspect: didn't you by any chance think you're in a
    C<for> loop or other construct creating an alias to $_, when in fact
    you're not?


    Michele
    --
    {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
    (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
    ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
    256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,

  6. Default Re: printing a subject line



    "Michele Dondi" <bik.mido@tiscalinet.it> wrote in message
    news:la5dh3t7qnrv56d4rl9to2mmuvrngphrqd@4ax.com...
    > On Wed, 17 Oct 2007 15:01:24 -0700, "Wade Ward" <zaxfuuq@invalid.net>
    > wrote:
    >
    >># Disconnect from the NNTP server
    >>$nntp->quit;
    >>
    >>my $subject = $_->[$subject_offset];

    >
    > Due to severe lack of time, I didn't read the whole code, but that
    > looks suspiscious: what is $_ at that point?!? Why should it contain
    > an arrayref? Suspect: didn't you by any chance think you're in a
    > C<for> loop or other construct creating an alias to $_, when in fact
    > you're not?

    On the one hand, a background in C is good for learning perl, OTOH, not so
    much.

    I kept on whittling down the output until I got what I wanted. The debugger
    was a huge help. When I got nothing for
    my $subject =$_->[$subject_offset]
    , when I typed p $subject1 in the debugger, then I was in hot pursuit of a
    soln.
    The end of the script now looks like:

    my $subject1 = "tja\n";
    my $s2 = join("\n", map ($_->[$subject_offset].'f
    '.$_->[$from_offset],@xover)),"\n";
    my $s3 = join("\n", map ($_->[$subject_offset].'f ',@xover)),"\n";
    my $s4 = join("\n", map ($_->[$subject_offset],@xover)),"\n";

    print join("\n", map ($_->[$subject_offset].' from '.$_->[$from_offset],
    @xover)),"\n";
    print $subject1;
    print STDOUT " s2 is $s2\n";
    print STDOUT " s3 is $s3\n";
    print STDOUT " s4 is $s4\n";
    __END__
    , and the output is:
    Re: printing a subject line from Michele Dondi <bik.mido@tiscalinet.it>
    tja
    s2 is Re: printing a subject linef Michele Dondi <bik.mido@tiscalinet.it>
    s3 is Re: printing a subject linef
    s4 is Re: printing a subject line

    ^^^^
    |
    |
    success

    Thx Charlton & Michele for help. A couple questions:
    Q1) What is map doing here:
    my $s2 = join("\n", map ($_->[$subject_offset].'f
    '.$_->[$from_offset],@xover)),"\n";
    Q2) What is the first newline doing in the join here:
    my $s4 = join("\n", map ($_->[$subject_offset],@xover)),"\n";
    --
    wade ward
    "Nicht verzagen, Bruder Grinde fragen."



  7. Default Re: printing a subject line



    "Michele Dondi" <bik.mido@tiscalinet.it> wrote in message
    news:la5dh3t7qnrv56d4rl9to2mmuvrngphrqd@4ax.com...
    > On Wed, 17 Oct 2007 15:01:24 -0700, "Wade Ward" <zaxfuuq@invalid.net>


    > Due to severe lack of time, I didn't read the whole code, but that
    > looks suspiscious: what is $_ at that point?!? Why should it contain
    > an arrayref? Suspect: didn't you by any chance think you're in a
    > C<for> loop or other construct creating an alias to $_, when in fact
    > you're not?

    Oh, and since you mention C and presumably know more Italian than I, can you
    help me translate this:

    Wade Ward ha scritto:
    > [repost]
    > [snipped from elsewhere]
    >
    >
    >>> I can't see how to cast an integer to a pointer.
    >>>

    >
    >
    >> You can't. Fortran doesn't do that - not even with the C interop stuff.
    >> Of course,you can always play around with TRANSFER, but recall that the
    >> standard says that the resulting values are undefined when you type
    >> cheat with TRANSFER. And you can do it in C.
    >>

    >
    > You can't do it portably in C, either. I believe you can memcpy() in
    > to an (unsigned char *) and back again. If sizeof(int) >= sizeof(void*)
    > you might be able to do the cast, but the use of the value of the
    > int is non-portable. Those writing large model x86 code, and
    > who try to do such casts, know all about this one.
    >
    >
    >>> cptr = C_PTR(p+1)
    >>>

    >
    >
    >> I suppose you are trying to use a structure constructor here. You can't
    >> do that with C_PTR as it has (intentionally) private components. The
    >> whole point of private components is to keep you from fiddling with the
    >> innards. You can't write a structure constructor for a private component
    >> - you don't even know what the components are. Now maybe you know what a
    >> C pointer better look like inside, but accordingh to the Fortran
    >> compiler, you don't know.
    >>

    >
    > From K&R2 (close, but not exactly, the C89 standard) A6.6:
    >
    > "Certain other conversions involving pointers and integers are
    > permitted, but have implementation defined aspects. They must
    > be specified by an explicit type-conversion operator, or cast."
    >

    Ovvero, per esempio, se
    void* pippo;
    long pluto;

    Puoi assegnare pluto a pippo, ma con un recast di pluto:
    pippo=(void*)pluto;
    > "A pointer may be converted to an integral type large enough to
    > hold it; the required size is implementation-dependent. The
    > mapping function is also implementation dependent."
    >

    Ovvero, puoi assegnare il valore di un pointer ad una variabile
    pluto=(long)pippo;

    ma la variabile deve potere contenere il valore del pointer: se il
    pointer e' un 32bit, occore
    usare un tipo da 32 bit almeno... questo dipende dall' architettura del
    processore.
    Su un processore a 16bit, con 16bit di indirizzamento, un pointer e' un
    16bit e basta un int.
    Su processore a 32bit con 32bit di indirizzo ci vuole un tipo da 32bit
    (di solito ma non
    necessariamente, un long: basterebbe un int ma su alcuni 32bit, gli int
    possono essere a 16bit..)

    > "An object of integral type may be explicitly converted to a
    > pointer. The mapping always carries a sufficiently wide integer
    > converted from a pointer back to the same pointer, but is
    > otherwise implementation-dependent."
    >
    >

    Vedi sopra; Puoi assegnare pluto a pippo, ma con un recast e pluto deve
    avere la stessa dimensione
    fisica di pippo (se pippo e' 32bit, pluto deve essere almeno da 32bit,
    salvo casi particolari ;-) )
    pippo=(void*)pluto;
    >

    Puņ qualcuno che conosca questo soggetto commentare il suddetto?


    A questo uno potrebbe chiedersi il perche' di tutte queste cose....
    In realta' lo scambio interi/pointers ha solo alcune applicazioni
    abbastanza particolari e non dovrebbe essere abusato.
    Quella che mi viene in mente e' la gestione di hardware, con mappe
    di indirizzi espresse in valori interi che poi vengono assegnate
    a puntatori...
    Ad ogni modo, queste operazioni sono molto legare al tipo di architettura
    della CPU, alla dimensione dei tipi e quindi *poco* portabili, per cui.....

    wade@zaxfuuq.net .
    --
    wade ward
    "Nicht verzagen, Bruder Grinde fragen."



  8. Default Re: printing a subject line

    On Wed, 17 Oct 2007 17:25:11 -0700, "Wade Ward" <zaxfuuq@invalid.net>
    wrote:

    >> Due to severe lack of time, I didn't read the whole code, but that
    >> looks suspiscious: what is $_ at that point?!? Why should it contain
    >> an arrayref? Suspect: didn't you by any chance think you're in a
    >> C<for> loop or other construct creating an alias to $_, when in fact
    >> you're not?

    >On the one hand, a background in C is good for learning perl, OTOH, not so
    >much.


    Huh?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?

    >I kept on whittling down the output until I got what I wanted. The debugger


    I wouldn't regard that as a very good way of proceeding, where a
    better one would be to have some idea of what one is doing, but if you
    like that...


    Michele
    --
    {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
    (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
    ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
    256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,

  9. Default Re: printing a subject line

    On Wed, 17 Oct 2007 17:40:40 -0700, "Wade Ward" <zaxfuuq@invalid.net>
    wrote:

    >> Due to severe lack of time, I didn't read the whole code, but that
    >> looks suspiscious: what is $_ at that point?!? Why should it contain
    >> an arrayref? Suspect: didn't you by any chance think you're in a
    >> C<for> loop or other construct creating an alias to $_, when in fact
    >> you're not?

    >Oh, and since you mention C and presumably know more Italian than I, can you
    >help me translate this:


    Huh?!? (Again) Where in hell did I ever mention C at all?!?

    Re the translation: no, it's way too OT here. Write to me by email and
    I may be so gentle as to translate that for you.


    Michele
    --
    {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
    (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
    ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
    256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,

  10. Default Re: printing a subject line

    In article <7kceh35npon4kgm38t5hd4h7dsuch8qko7@4ax.com>,
    Michele Dondi <bik.mido@tiscalinet.it> wrote:
    >On Wed, 17 Oct 2007 17:40:40 -0700, "Wade Ward" <zaxfuuq@invalid.net>
    >wrote:
    >
    >>> Due to severe lack of time, I didn't read the whole code, but that
    >>> looks suspiscious: what is $_ at that point?!? Why should it contain
    >>> an arrayref? Suspect: didn't you by any chance think you're in a
    >>> C<for> loop or other construct creating an alias to $_, when in fact
    >>> you're not?

    >>Oh, and since you mention C and presumably know more Italian than I, can you
    >>help me translate this:

    >
    >Huh?!? (Again) Where in hell did I ever mention C at all?!?


    This part right here:

    >>> C<for> loop


    could very easily be interpreted as making a comparison to a C-language-style
    for loop by someone who has never seen POD source before, or didn't expect to
    see it in a post that otherwise contained only ordinary English text with
    some small perly bits.

    Putting undeclared POD markup in a Usenet message seems about as wise as
    putting in other kinds of undeclared markup.

    Although you might wish that every perl programmer document every program and
    every subroutine with inline POD, they don't. (In some cases, we're lucky if
    they \fIread\fR any documentation, let alone write it.)

    --
    Alan Curry
    pacman@world.std.com

+ Reply to Thread
Page 1 of 2 1 2 LastLast

Similar Threads

  1. Re: subject line
    By Application Development in forum RUBY
    Replies: 30
    Last Post: 09-07-2007, 12:19 PM
  2. Re: subject line
    By Application Development in forum RUBY
    Replies: 2
    Last Post: 09-04-2007, 06:17 PM
  3. Re: subject line
    By Application Development in forum RUBY
    Replies: 1
    Last Post: 09-03-2007, 01:21 PM
  4. Re: subject line
    By Application Development in forum RUBY
    Replies: 0
    Last Post: 09-02-2007, 08:32 PM
  5. Replies: 5
    Last Post: 05-02-2006, 09:25 PM