Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: accessing data in DBI object

by arcnon (Monk)
on Apr 14, 2005 at 17:06 UTC ( [id://447870]=note: print w/replies, xml ) Need Help??


in reply to Re: accessing data in DBI object
in thread accessing data in DBI object

I was just trying to get at 2 fields and change the data without having to create a new object. Which I did anyway...

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

    The only objects you have in this snippet are $dbh (a database handle object) and $sth (a statement handle object). (You called them $DBHandle and $DataOut in the original snippet.) The rest of the variables are just your ordinary garden variety variables: scalars, arrays and hashes. Objects are references (a scalar holding the address of another variable) that have been blessed into a given class. See perldata, perlref, perldsc, perllol, perlobj, perlmod, perltoot and perlboot for the complete details about Perl data types, references, Perl data structures, modules, and objects.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://447870]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-03-29 01:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found