A Perl Chicken-and-egg problem
Paul King
sciguy-Ja3L+HSX0kI at public.gmane.org
Sat Jun 21 19:32:10 UTC 2008
On Sat, 2008-06-21 at 14:58 -0400, Madison Kelly wrote:
> It is very common for module's methods to return array and hash
> references instead of a copy of an array or hash to save memory and
> improve speed. Try:
>
> my $A = myobj::files::list(params); // same declaration as in the docs
Yes, I thought about using "$A" instead of "@A". I just didn't know what
to do with it afterward. The code suggestion (Synopsis section) actually
uses @A. There are errors and vague stuff in other places in the docs
also. After get this module more or less figured out, I have a mind to
re-write the documentation. Where and how do I submit it? Anyone?
Paul King
> foreach $x (@{$A}) {
> print "$x\n";
> }
>
> Madi
>
> Paul King wrote:
> > Hello
> >
> > I dabble in Perl occasionally, and when I have to use modules or objects
> > in Perl, it is a dusty corner for me where the documentation is normally
> > unhelpful.
> >
> > I need to use an array which is in one of these modules -- the module
> > name is not important -- where the actual array is pointed to by the
> > variable it passes to me. For example,
> >
> > my @A = myobj::files::list(params); // same declaration as in the docs
> > foreach $x (@A) {
> > print "$x\n";
> > }
> >
> > yields nothing except a pointer to an array -- something like
> >
> > ARRAY(#A1B2C3D4)
> >
> > in the output. This causes me to have to alter my code to do this:
> >
> > my @A = myobj::files::list(params);
> > foreach $x (@A) {
> > for ($i = 0; $i < $max; $i++) {
> > print "$x->[$i]\n";
> > }
> > }
> >
> > This, I think, gives the output to the array pointed to by $x (I say "I
> > think", since my copy of O'Reilly's Programming Perl 2e says that you
> > dereference an array using "=>" not "->"). And the reality is worse,
> > since the module I am using actually returns a pointer to a
> > 2-dimensional array:
> >
> > my @A = myobj::files::list(params);
> > foreach $x (@A) {
> > for ($i = 0; $i < 16; $i++) {
> > for $j = 0; $j < 16; $j++) {
> > print "$x->[$i][$j]\n";
> > }
> > }
> > }
> >
> > This kind of works. I get the output I expect, except for one thing. I
> > don't know the array size, so I am hard-coding the upper limit of the
> > loops. $#x to find the size doesn't work, since (1) $x merely points to
> > an array, and (2) the array is two dimensional. Any suggestions?
> >
> > Paul King
> >
> >
> > --
> > The Toronto Linux Users Group. Meetings: http://gtalug.org/
> > TLUG requests: Linux topics, No HTML, wrap text below 80 columns
> > How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists
> >
>
> --
> The Toronto Linux Users Group. Meetings: http://gtalug.org/
> TLUG requests: Linux topics, No HTML, wrap text below 80 columns
> How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists
> r
--
The Toronto Linux Users Group. Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists
More information about the Legacy
mailing list