A Perl Chicken-and-egg problem

Richard Dice rdice-e+AXbWqSrlAAvxtiuMwx3w at public.gmane.org
Sat Jun 21 19:27:33 UTC 2008


What you want is a Perl module called Data::Dumper.  It is completely
brilliant.  It should come packaged with your Perl.  Otherwise, install it
from CPAN.

"use Data::Dumper qw ( Dumper );" should go at the top of your program.  And
then,

print Dumper(\@A);

This would show you marvellous things about your data structure.  It's
essential for debugging and otherwise understanding what your complex data
structures look like.

Cheers,
 - Richard

On Sat, Jun 21, 2008 at 3:27 PM, Paul King <sciguy at vex.net> wrote:

> 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 at vex.net>:
> > > 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 at gmail.com>
> > N 'T .Ǟ) m൩n2 - h',60+j^ޖ<%i -CRP DDi-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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://gtalug.org/pipermail/legacy/attachments/20080621/a3ab4437/attachment.html>


More information about the Legacy mailing list