Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Reading & Posting Usenet News Messages

Reply
Thread Tools

Reading & Posting Usenet News Messages

 
 
Camelback Jones
Guest
Posts: n/a
 
      02-17-2004
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.

 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      02-17-2004
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
 
Reply With Quote
 
 
 
 
James Taylor
Guest
Posts: n/a
 
      02-17-2004
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.

 
Reply With Quote
 
Camelback Jones
Guest
Posts: n/a
 
      02-17-2004
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.

 
Reply With Quote
 
Camelback Jones
Guest
Posts: n/a
 
      02-17-2004
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.

 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      02-17-2004
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Usenet abuse (addressed to Usenet admins) Mike Easter Computer Support 5 01-18-2010 09:18 AM
Re: Usenet abuse (addressed to Usenet admins) Tony Computer Support 0 01-17-2010 06:05 PM
Breaking news.."We have latest news in leo technology news" Leo C Programming 0 06-30-2009 09:24 PM
Problems with posting email/news messages via OE6 and working with Web-based email Alex Vinokur Computer Support 2 06-18-2004 12:56 PM
Posting Usenet News Messages Camelback Jones Perl Misc 24 02-23-2004 02:47 AM



Advertisments