Yes!  Data::Dumper is very cool!

And then you can 'print Dumper' down whatever hash or array trail it leads you down; 
if it prints HASH or ARRAY then you know you need to add another {} or [] and you can 
work out empirically (the hard way!) what syntax you need.

I just got through doing this with the XML::Simple and HTML:TreeBuilder modules.  Boy 
do THEY make some deep mess!

You are probably already using 'perl -w' and 'use strict'.  Another one is 'use 
diagnostics'; this makes for very verbose error messages.

Gregory L. Hering
4807 Bradford Drive
Huntsville, AL 35805
(256) 722-6420


> -----Original Message-----
> From: Keith Jackson [mailto:[EMAIL PROTECTED] 
> Sent: Thursday, July 24, 2003 7:09 AM
> To: [EMAIL PROTECTED]
> Cc: John Brahy
> Subject: Re: reference/dereference goto trash
> 
> 
> To help understand the structures returned by the various DBI 
> functions I use Data::Dumper.  It helps visualize the data structure.
> 
> In your case:
> 
> use Data::Dumper;
> 
> print Dumper(getAddress($clientID);
> 
> Data::Dumper is great for debugging.
> 
> HTH
> 
> On Wed, 2003-07-23 at 19:35, Michael A Chase wrote:
> > On Wed, 23 Jul 2003 01:23:11 -0800 (AKDT) John Brahy 
> > <[EMAIL PROTECTED]> wrote:
> > 
> > > I'm going nuts with the references here.... can anyone give me a 
> > > sanity check? How do I get the data out of the address 
> array? all I 
> > > get is:
> > > Home Phone:   ARRAY(0x83a0f88)
> > > 
> > > my @address   = @{ getAddress($clientID)};
> > > my $homePhone = $address[0] || "n/a";
> > 
> > This returns an array reference for the contents of row0, the first 
> > row.
> > 
> > > sub getAddress {
> > >   my ($clientID) = @_;
> > >   use PfTV::Auth;
> > >   my $auth = new PfTV::Auth;
> > >   my $dbh = 
> DBI->connect($auth->dsn,$auth->username,$auth->password) 
> > > || die "COULDN'T CONNECT";
> > >   my $sql = "select AddressID, ClientID, StatusID, Street, City, 
> > > State, ZipCode, HomePhone, CellPhone, Pager, Fax, WorkPhone from  
> > > Addresses WHERE ClientID = $clientID";
> > >   my $sth = $dbh->prepare($sql);
> > >   $sth->execute;
> > >   return $sth->fetchall_arrayref;
> > > }
> > 
> > What's returned by getAddress() is an array of arrays
> > [[row0],[row1],[row2],...]:
> > 
> >    my $addresses = getAddress( $clientID );
> >    my ( $row, $AddressID, $CliendID, $StatusID, $Street, $City,
> >         $State, $ZipCOde, $HomePage, $CellPhone, $Pager, $Fax,
> >         $WorkPhone );
> >    foreach $row ( @$addresses ) {
> >       ( $AddressID, $CliendID, $StatusID, $Street, $City,
> >         $State, $ZipCOde, $HomePage, $CellPhone, $Pager, $Fax,
> >         $WorkPhone ) = @$row;
> >       # Do something with the row's values.
> >    }
> -- 
> Keith Jackson <[EMAIL PROTECTED]>
> 
> 

Reply via email to