Find the answer to your Linux question:
Results 1 to 8 of 8
Like Tree2Likes
  • 1 Post By gregm
  • 1 Post By sayhello
hello dear Linux - experts i am pretty new to per.l - and i want to do the first steps to store some values: how to put the output of ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Newbie
    Join Date
    May 2013
    Posts
    212

    store the output in mysql - instead of printing


    hello dear Linux - experts


    i am pretty new to per.l - and i want to do the first steps to store some values:
    how to put the output of the request to the db

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

    see
    https://metacpan.org/source/LBROCARD...rs-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


    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:umper?
    Akoya P 6512 15" OpenSuse 13.1: AMD Athlon X2 P320
    Samsunng q 210, 12,1" OpenSuse 13.1: Intel® Core™ 2 Duo Proz. P8400 2,26 GHz 1066 MHz FSB 3 MB

  2. #2
    Linux Engineer docbop's Avatar
    Join Date
    Nov 2009
    Location
    Woodshed, CA
    Posts
    943
    Do you know basic SQL commands and how to create a database, tables, and input and select data? If so then there is a perl module for accessing MySQL from perl.

    DBD::mysql - search.cpan.org


    If you don't know SQL then here's a like to the W3C that has tutorials on all things internet.

    SQL Tutorial

    W3C is a good place to get started with lots of programming and web topics.
    A lion does not lose sleep, over the opinion of sheep.

  3. #3
    Linux Newbie
    Join Date
    May 2013
    Posts
    212
    hello dear cdocbop

    many many thanks for this great hints - superb-startingpoints.

    thx for this
    i will dig deeper into all that




    But instead of printing the data, we need to have insert it into the db.

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

    I CAN create the database?
    I THINK THAT I KNOW how to connect to the database from THE script?
    BUT I DO NOT know how to write the insert statement?

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


    CAN YOU lend me a helpin hand

    thanks in advance
    Last edited by sayhello; 06-07-2014 at 08:03 PM.
    Akoya P 6512 15" OpenSuse 13.1: AMD Athlon X2 P320
    Samsunng q 210, 12,1" OpenSuse 13.1: Intel® Core™ 2 Duo Proz. P8400 2,26 GHz 1066 MHz FSB 3 MB

  4. #4
    Linux Engineer docbop's Avatar
    Join Date
    Nov 2009
    Location
    Woodshed, CA
    Posts
    943
    The MySQL website is a great place to start looking for answers to MySQL questions.

    The easiest way to get started to create your database first in mysql then you only have to write code for your program to update and read the data. So first you need to create a database, then create a table where you will put your data. A database can have one to hundreds of tables. So below is the mysql page on creating tables.

    https://dev.mysql.com/doc/refman/5.7...ng-tables.html
    A lion does not lose sleep, over the opinion of sheep.

  5. #5
    Linux Newbie
    Join Date
    May 2013
    Posts
    212
    good morning dear docbop - great to hear from you again!

    d a very very good tutorial that shows how easy that one can be made with php

    http://dalibor.dvorski.net/downloads...gWithXAMPP.pdf


    it is very very simple - in PHP. i am going to see if we can do such an easy solution in perl - which is in general a bit more difficult than php - (my opinion)
    Akoya P 6512 15" OpenSuse 13.1: AMD Athlon X2 P320
    Samsunng q 210, 12,1" OpenSuse 13.1: Intel® Core™ 2 Duo Proz. P8400 2,26 GHz 1066 MHz FSB 3 MB

  6. #6
    Linux Engineer docbop's Avatar
    Join Date
    Nov 2009
    Location
    Woodshed, CA
    Posts
    943
    Quote Originally Posted by sayhello View Post
    good morning dear docbop - great to hear from you again!

    d a very very good tutorial that shows how easy that one can be made with php

    http://dalibor.dvorski.net/downloads...gWithXAMPP.pdf


    it is very very simple - in PHP. i am going to see if we can do such an easy solution in perl - which is in general a bit more difficult than php - (my opinion)
    Perl is one of those things you either love or hate. Perl gives me a headache.
    A lion does not lose sleep, over the opinion of sheep.

  7. #7
    Linux Engineer
    Join Date
    Dec 2013
    Posts
    1,317
    “Perl – The only language that looks the same before and after RSA encryption.”
    ― Keith Bostic
    docbop likes this.

  8. #8
    Linux Newbie
    Join Date
    May 2013
    Posts
    212
    hello you both

    thx for that great comment

    Quote Originally Posted by gregm View Post
    “Perl – The only language that looks the same before and after RSA encryption.”
    ― Keith Bostic
    i like them.... - and i think that i ve got a headache too


    docbop likes this.
    Akoya P 6512 15" OpenSuse 13.1: AMD Athlon X2 P320
    Samsunng q 210, 12,1" OpenSuse 13.1: Intel® Core™ 2 Duo Proz. P8400 2,26 GHz 1066 MHz FSB 3 MB

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •