CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [dilbert] storing values to mySQL - with DBI: Edit Log



FishMonger
Veteran / Moderator

Jun 7, 2014, 6:53 AM


Views: 6939
Re: [dilbert] storing values to mySQL - with DBI

There's no reason/need to use the Storable module if you're planning on putting the data into a database.

@authors is an array of objects. You need to loop over that array and insert each author's info into the DB.

You could use the Data::Dumper module to inspect/review the structure of the @authors array. For example, if you add a print Dumper \@authors; statement your output would look like this:

Code
acme@astray.com 
Leon Brocard
LBROCARD
$VAR1 = [
bless( {
'name' => 'Neil Hainer',
'email' => 'CENSORED',
'pauseid' => 'NHAINER'
}, 'Parse::CPAN::Authors::Author' ),
bless( {
'pauseid' => 'CROSSWIRE',
'email' => 'matt@crosswire.com',
'name' => 'Matthew Sibley'
}, 'Parse::CPAN::Authors::Author' ),
bless( {
'pauseid' => 'DAVIDJNSN',
'name' => 'David Jensen',
'email' => 'CENSORED'
}, 'Parse::CPAN::Authors::Author' ),
bless( {
'pauseid' => 'KESZLER',
'name' => 'Scott R. Keszler',
'email' => 'keszler@srkconsulting.com'
}, 'Parse::CPAN::Authors::Author' ),


This is how you'd loop over the array.

Code
for my $author ( @authors ) { 
print $author->email, "\n";
print $author->name, "\n";
print $author->pauseid, "\n\n";
}

But instead of printing the data, you would insert it into the db.

The DB table will need the 3 fields to hold the author's ID, name, and email address.

Have you created the database?
Do you know how to connect to the database from your script?
Do you know how to write the insert statement?

Reading over the DBI and DBD::mysql module documentation will answer those questions.


(This post was edited by FishMonger on Jun 7, 2014, 6:59 AM)


Edit Log:
Post edited by FishMonger (Veteran) on Jun 7, 2014, 6:57 AM
Post edited by FishMonger (Veteran) on Jun 7, 2014, 6:59 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives