A Perl Chicken-and-egg problem

Paul King sciguy-Ja3L+HSX0kI at public.gmane.org
Sat Jun 21 19:27:52 UTC 2008


Thanks for referring me to perlref. I recall that it is possible to
actually reverse-engineer the data structure of the module being called.
Is it in perlref, or is it somewhere else?

Paul King

On Sat, 2008-06-21 at 15:05 -0400, Seneca Cunningham wrote:
> 2008/6/21 Paul King <sciguy-Ja3L+HSX0kI at public.gmane.org>:
> > 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?
> 
> If you care about the indices, you could use the form:
> 
>   foreach my $x (@A) {
>      foreach my $i (0 .. (@$x -1)) {
>           foreach my $j (0 .. (@{$x->[$i]} - 1)) {
>                print "$x->[$i][$j]\n";
>           }
>      }
>   }
> 
> If you don't care about the indices, you could use the form:
> 
>   foreach my $x (@A) {
>      foreach my $i (@$x) {
>           foreach my $j (@$i) {
>                print "$j\n";
>           }
>      }
>   }
> 
> Both forms rely upon dereferencing the arrayrefs.  The perldoc page
> "perlref" has more details about referencing and dereferencing values.
> 
> -- 
> Seneca Cunningham
> <tentra-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org>
> N'T.Ǟ)m൩n2-h',60+j^ޖ<%i
-CRPDDi-j[?)"Ƣ)+-

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