Reading & Posting Usenet News Messages

Discussion in 'Perl Misc' started by Camelback Jones, Feb 17, 2004.

  1. Yep, that's ol' # 18.4 from O'Reilly's Perl Cookbook.

    It seems to work okay, except that when trying to print the results of, for
    example,

    $bodytext = $server->body($first) or die "aaaargh!!!\n";

    all I can get is ARRAY(<some memory address>).

    I've tried printing $bodytext[0], it's blank. I've tried a foreach loop,
    also blanks... I'm pretty sure the body isn't really blank, because the
    header does the same thing... No doubt I'm doing something stupid either in
    the retrieval or the print, but I haven't been able to print anything other
    than ARRAY(whatever) or blank...

    I know this is ignorance on my part, but I've tried all the examples I can
    find in various "Printing Array Contents" helpful hints, with nothing
    resulting except the same (*&#@$ thing. And it doesn't seem to matter what
    newsgroups I pick - this one, alt.test, alt.conspiracy, rec.woodworking...
    whatever.

    Any ideas?


    --
    The greatest unsolved problem in mathematics is why some people are
    better at it than others.
    Camelback Jones, Feb 17, 2004
    #1
    1. Advertising

  2. Camelback Jones

    Paul Lalli Guest

    On Tue, 17 Feb 2004, Camelback Jones wrote:

    > Yep, that's ol' # 18.4 from O'Reilly's Perl Cookbook.
    >
    > It seems to work okay, except that when trying to print the results of, for
    > example,
    >
    > $bodytext = $server->body($first) or die "aaaargh!!!\n";
    >
    > all I can get is ARRAY(<some memory address>).
    >
    > I've tried printing $bodytext[0], it's blank. I've tried a foreach loop,
    > also blanks... I'm pretty sure the body isn't really blank, because the
    > header does the same thing... No doubt I'm doing something stupid either in
    > the retrieval or the print, but I haven't been able to print anything other
    > than ARRAY(whatever) or blank...



    $bodytext has nothing to do with $bodytext[0]. $bodytext, as assigned
    above, is an array reference. $bodytext[0] is the first element of an
    array named @bodytext. $bodytext and @bodytext have nothing to do with
    each other. If you want to print out the array referenced by $bodytext,
    you have a few choices:

    Dereference and copy the entire array:
    @body = @$bodytext;
    print "Body: @body\n";

    Dereference the array only:
    print "Body: @$bodytext\n";

    print just the element of the referenced array you want:
    print "Body line $i: $$bodytext[$i]\n";
    or
    print "Body line $i: $bodytext->[$i]\n";

    Please take a look at
    perldoc perlref
    for more information.

    Paul Lalli
    Paul Lalli, Feb 17, 2004
    #2
    1. Advertising

  3. Camelback Jones

    James Taylor Guest

    In article <>,
    Camelback Jones <> wrote:
    >
    > Yep, that's ol' # 18.4 from O'Reilly's Perl Cookbook.
    >
    > It seems to work okay, except that when trying to print the results
    > of, for example,
    >
    > $bodytext = $server->body($first) or die "aaaargh!!!\n";
    >
    > all I can get is ARRAY(<some memory address>).
    >
    > I've tried printing $bodytext[0], it's blank.


    Err... forgive me if this is wrong because I've never used
    Net::NNTP but surely if $bodytext is an array reference then
    you shouldn't access it as $bodytext[0], instead you should
    access it as either $$bodytext[0] or $bodytext->[0].

    --
    James Taylor, Cheltenham, Gloucestershire, UK. PGP key: 3FBE1BF9
    To protect against spam, the address in the "From:" header is not valid.
    In any case, you should reply to the group so that everyone can benefit.
    If you must send me a private email, use james at oakseed demon co uk.
    James Taylor, Feb 17, 2004
    #3
  4. James Taylor wrote:

    > In article <>,
    > Camelback Jones <> wrote:
    >>
    >> Yep, that's ol' # 18.4 from O'Reilly's Perl Cookbook.
    >>
    >> It seems to work okay, except that when trying to print the results
    >> of, for example,
    >>
    >> $bodytext = $server->body($first) or die "aaaargh!!!\n";
    >>
    >> all I can get is ARRAY(<some memory address>).
    >>
    >> I've tried printing $bodytext[0], it's blank.

    >
    > Err... forgive me if this is wrong because I've never used
    > Net::NNTP but surely if $bodytext is an array reference then
    > you shouldn't access it as $bodytext[0], instead you should
    > access it as either $$bodytext[0] or $bodytext->[0].
    >



    Tried those - no joy. See next response.

    --
    The greatest unsolved theorem in mathematics is why some people are
    better at it than others.
    Camelback Jones, Feb 17, 2004
    #4
  5. Paul Lalli wrote:

    > On Tue, 17 Feb 2004, Camelback Jones wrote:
    >


    > $bodytext has nothing to do with $bodytext[0]. $bodytext, as assigned
    > above, is an array reference. $bodytext[0] is the first element of an
    > array named @bodytext. $bodytext and @bodytext have nothing to do with
    > each other. If you want to print out the array referenced by $bodytext,
    > you have a few choices:
    >
    > Dereference and copy the entire array:
    > @body = @$bodytext;
    > print "Body: @body\n";
    >
    > Dereference the array only:
    > print "Body: @$bodytext\n";
    >
    > print just the element of the referenced array you want:
    > print "Body line $i: $$bodytext[$i]\n";
    > or
    > print "Body line $i: $bodytext->[$i]\n";
    >


    Those work. Thank you.


    > Please take a look at
    > perldoc perlref
    > for more information.


    Actually, I did. I was looking for information on array references, and
    apparently I wasn't creative enough to give them what they wanted. The
    reference on Net::NNTP told me what the methods are returning, but I
    couldn't find the dereferencing information.

    Again, thank you.

    --
    The greatest unsolved theorem in mathematics is why some people are
    better at it than others.
    Camelback Jones, Feb 17, 2004
    #5
  6. Camelback Jones <> wrote:

    > $bodytext = $server->body($first) or die "aaaargh!!!\n";
    >
    > all I can get is ARRAY(<some memory address>).

    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^


    That is the form for a stringified array reference.

    You printed the reference itself, rather that dereferencing the reference.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Feb 17, 2004
    #6
    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. Fernando

    Usenet posting wiht python

    Fernando, Sep 12, 2003, in forum: Python
    Replies:
    2
    Views:
    847
    Peter Scott
    Sep 12, 2003
  2. Replies:
    0
    Views:
    355
  3. richard
    Replies:
    7
    Views:
    1,413
    Allodoxaphobia
    Jan 10, 2011
  4. Camelback Jones

    Posting Usenet News Messages

    Camelback Jones, Feb 17, 2004, in forum: Perl Misc
    Replies:
    24
    Views:
    257
    Joe Smith
    Feb 23, 2004
  5. simil

    usenet posting of perl release

    simil, Sep 7, 2007, in forum: Perl Misc
    Replies:
    4
    Views:
    217
    Douglas Wells
    Sep 8, 2007
Loading...

Share This Page