Reading & Posting Usenet News Messages

C

Camelback Jones

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?
 
P

Paul Lalli

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
 
J

James Taylor

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].
 
C

Camelback Jones

James said:
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.
 
C

Camelback Jones

Paul said:
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.
 
T

Tad McClellan

Camelback Jones said:
$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.
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top