Perl Hashes and MySQL database

Discussion in 'Perl Misc' started by Andreas Sonnenbichler, Sep 1, 2003.

  1. Hello,

    maybe, its a too simple question, but I don't know where to start:

    I have a extremely big hash (almost 1GB mem), looking like this:
    $hash->{$id}->{$row}.

    I want to store this hash in ONE MySQL database table, so that $id marks one
    db entity, and all keys (in row) are stored together in one other db field.

    Like this:
    +++++++++++++++++++++++++++++++++++++++++
    + ID + Value +++++++++++++++++++++++++++
    +++++++++++++++++++++++++++++++++++++++++
    + id1 + id1-row1, id1-row2, id1-row3, ...
    + id2 + id2-row1, id1-row3, id1-row7, ...

    Is there any FAST possibility. I mean, of course I can concatenate all
    row-values and write the resulting hash manually by any loop writeing all
    id's. But is there something thats makes it faster? Like tieing or so?

    Andreas
    Andreas Sonnenbichler, Sep 1, 2003
    #1
    1. Advertising

  2. Andreas Sonnenbichler

    Ingo Wiarda Guest

    Andreas Sonnenbichler wrote:

    > I have a extremely big hash (almost 1GB mem), looking like this:
    > $hash->{$id}->{$row}.
    >
    > I want to store this hash in ONE MySQL database table, so that $id marks
    > one db entity, and all keys (in row) are stored together in one other db
    > field.
    >
    > Like this:
    > +++++++++++++++++++++++++++++++++++++++++
    > + ID + Value +++++++++++++++++++++++++++
    > +++++++++++++++++++++++++++++++++++++++++
    > + id1 + id1-row1, id1-row2, id1-row3, ...
    > + id2 + id2-row1, id1-row3, id1-row7, ...
    >
    > Is there any FAST possibility. I mean, of course I can concatenate all
    > row-values and write the resulting hash manually by any loop writeing all
    > id's. But is there something thats makes it faster? Like tieing or so?


    1. You want all keys in one big string to put them into the Value column.
    Seems like you will only accomplish this by concatenation: eg,
    join(",", keys $hash->{$id});
    2. Tie could make read/write access to the db easier, but not faster, if you
    are going to cram the whole hash into the db at once.
    3. How fast (and what) is your current approach? Have you tried dumping the
    hash to a file and importing it into MySQL via "load data infile" (I used
    this for a 160 MB file)?

    Ingo

    --
    http://dewarim.de
    Ingo Wiarda, Sep 1, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Holness

    Hashes of Hashes via subs

    Ben Holness, Oct 5, 2003, in forum: Perl
    Replies:
    8
    Views:
    559
    Ben Holness
    Oct 8, 2003
  2. Steven Arnold

    using hashes as keys in hashes

    Steven Arnold, Nov 23, 2005, in forum: Ruby
    Replies:
    3
    Views:
    159
    Mauricio Fernández
    Nov 23, 2005
  3. kazaam
    Replies:
    12
    Views:
    267
    Matthias Wächter
    Sep 13, 2007
  4. Tim O'Donovan

    Hash of hashes, of hashes, of arrays of hashes

    Tim O'Donovan, Oct 27, 2005, in forum: Perl Misc
    Replies:
    5
    Views:
    207
  5. Replies:
    3
    Views:
    205
Loading...

Share This Page