Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Wed 23 Jul 2014, 16:18
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
How to store the Perl output - instead of printing?
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [2 Posts]  
Author Message
sayhello_to_the_world

Joined: 24 Dec 2012
Posts: 41

PostPosted: Sat 07 Jun 2014, 07:29    Post subject:  How to store the Perl output - instead of printing?  

goo day

new to perl - want to store the output - instead of printing out

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;
     
     
     
     



what do i want to do: i want to store all the output in the mysql-db

how to put the output of the request to the db

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


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




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?
Back to top
View user's profile Send private message 
GustavoYz


Joined: 07 Jul 2010
Posts: 895
Location: .ar

PostPosted: Wed 11 Jun 2014, 17:27    Post subject:  

Hi, Im not understanding the question.
What do you mean by serialize it?

As long as you have the data retrieved, store it is easy as make a query, prepare and run it (use placeholders '?' wisely). If the structure is complex, you may need to find a procedure to retrieve it in order, but thats specific: it depends on the problem to solve.

Being a generic scenario, Ill post you a generic function (Razz) I use sometimes. It will print nested data structures, hash and arrays. May be of use, maybe not.

Code:

sub iterate {
    my $input = shift;
    unless (ref $input) {
        print "$input\n";
    } elsif (ref $input eq 'ARRAY') {
        iterate($_) for @$input;
    } elsif (ref $input eq 'HASH') {
        for (keys %$input) {
            print "$_\n";
            iterate($input->{$_});
        }
    } else {
        print ref $input,"\n";
    }
}

_________________

Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [2 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0466s ][ Queries: 11 (0.0037s) ][ GZIP on ]