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: Intermediate:
store the values in a mysql db instead of printing out

 



dilbert
User

Jun 4, 2014, 12:25 PM

Post #1 of 3 (8252 views)
store the values in a mysql db instead of printing out Can't Post

hello dear perl experts


i do my very first steps in perl - i have installed perl on opensuse 13.1 - and a database mysql is also up and running.


now i want to do some little requests - and store the results in the mysql-db.

how to put the output of the request to the db


Parse::CPAN::Authors;


also i have perl :: DBI installed
also the mysql-db is up and running



https://metacpan.org/source/LBROCARD/Parse-CPAN-Authors-2.27/README


Code
  use Parse::CPAN::Authors; 

# must have downloaded
my $p = Parse::CPAN::Authors->new("01mailrc.txt.gz");
# either a filename as above or pass in the contents of the file
my $p = Parse::CPAN::Authors->new($mailrc_contents);

my $author = $p->author('LBROCARD');
# $a is a Parse::CPAN::Authors::Author object
# ... objects are returned by Parse::CPAN::Authors
print $author->email, "\n"; # leon@astray.com
print $author->name, "\n"; # Leon Brocard
print $author->pauseid, "\n"; # LBROCARD

# all the author objects
my @authors = $p->authors;




i want to store all the output in the mysql-db


Laurent_R
Veteran / Moderator

Jun 4, 2014, 3:10 PM

Post #2 of 3 (8194 views)
Re: [dilbert] store the values in a mysql db instead of printing out [In reply to] Can't Post

Well, if you are doing your very first steps in Perl, maybe you should post in the beginner section, rather than the intermediate section.

Tongue

Then, the questions are:
- where do you encounter problems,
- what have you done so far,
- did you write some code relative to DB management
- do you know how to use SQL ?
- have you create your DB tables, what do they look like ?
- do you have trouble with perl, with SQL or with the DBI module?

There is really nothing complicated in what you want to do, it is quite straight forward, but it is a relatively long list of steps, any one of them might be a roadblock for you if you don't know how to handle it. In brief, we don't have a clue on where you are having problems.


dilbert
User

Jun 5, 2014, 1:40 PM

Post #3 of 3 (7740 views)
Re: [Laurent_R] store the values in a mysql db instead of printing out [In reply to] Can't Post

 
hello dear Laurent,



first of all - many thanks

your re right: to post this in the beginner-forum would be a better idea.


regarding the db-things: well i am pretty new to perl-tasks.

but with the above mentioned module - i think i can learn alot - it is quite very simple. And with this i can play around - and try to find out how to store the data into a mysql db.


well could the results that i get be regarded as a perl object (reference to array of references) like the below:


Code
my $a = [ [$a, $ab, $c ], [$a, $b, $c] ] ;


and need to store it on the DB then retrieve it.

i look for a good mechanism to serialize it and then store it on the DB?


hmm - if i want to store:


Code
use Storable 
use DBI;

# ... connect to database
# Store
my $data = [ [$a, $b, $c ], [ $a, $b, $c ] ];
my $bytestream = nfreeze $data;
$dbh->do('insert into table (field) values(?)', undef, $bytestream);


by the way: What about Data::Dumper? We could dump the objects into a TEXT field of the DB and then eval the content to get it back.


And perldoc says the return value of Data::Dumper can be "evaled to get back an identical copy of the original reference structure". we could then put the Dumper output into a large enough text field in the database.


love to hear from you
greetings

 
 


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

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