in reply to Re: accessing data in DBI object
in thread accessing data in DBI object
I alway use strict. Yes it throws errors which just told me I wasn't accessing the structure right. But I already knew that. :)
References eat my lunch anyway. I use objects to dodge them to avoid @{}->[]->{} crap. So when I have to work with them(refs) I am always lost. my solution was as follows
$Query_Statement="select fname,lname,address,city,state,zip,phone,emai +l FROM main order by lname,fname;"; my $sth = $dbh->prepare($Query_Statement); $sth->execute(); my @array; my $dataObjRef = \@array; while( my $array_ref = $sth->fetchrow_arrayref){ #print ">>@$array_ref\n"; my $fname = $array_ref->[0]; my $lname = $array_ref->[1]; my $total += length($fname); my $total += length($lname); if ((length($fname) + length($lname)) > 18){ my $Fintial = substr($fname,0,1); if ((length($Fintial) + length($lname)) > 18){ $lname = substr($lname,0,16); } $array_ref->[0] = $Fintial; $array_ref->[1] = $lname; #print "$Fintial $lname\n"; } else{ next; } my @newArray = @$array_ref; push(@$dataObjRef, \@newArray); } $sth->finish(); $dbh->disconnect or warn "Disconnection failed: $DBI::errstr\n"; return $dataObjRef; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: accessing data in DBI object
by Mr. Muskrat (Canon) on Apr 15, 2005 at 01:37 UTC |