in reply to Re: HOW TO CREATE A DATABASE FILE WITH FIELDS IN RECORDS
in thread HOW TO CREATE A DATABASE FILE WITH FIELDS IN RECORDS

I wouldn't suggest using pack and unpack to build a database. But you can build your own databases without having to buy an external database. You can use MySql or even build a database out of text files using DBD::CSV, for example, or use one of the DB_FILE modules. You might want to try http://search.cpan.org/ for more details and more ideas. Sorry, I don't actually do much of this kind of stuff.

        - tye (but my friends call me "Tye")
  • Comment on (tye)Re: HOW TO CREATE A DATABASE FILE WITH FIELDS IN RECORDS

Replies are listed 'Best First'.
Re: (tye)Re: HOW TO CREATE A DATABASE FILE WITH FIELDS IN RECORDS
by extremely (Priest) on Dec 27, 2000 at 18:15 UTC
    "I wouldn't suggest using pack and unpack to build a database."

    I would. In fact, that is historically exactly what they are for. On the other hand, I wouldn't suggest building your own database when there are perfectly good ones out there so it is rather moot. =)

    If your needs are lightweight and the data sets are small you should likely try DBD::CSV or even just something like:

    #!/usr/bin perl -w use strict; use Data::Dumper; my @LoL = ( ["aa", 1, 2, 3, "Hi Mom!"], ["bb", 2, 3, 5, "No soup for you!"], ["cc", 3, 1, 2, "Not me!"], ["def", 4, 4, 4, "Like gag me with a spoon!"], ); { #block for localizing open FOUT, ">./datafile"; local $\=$/; #Record separator set to input separator. local $"=$;; #Array interpolation separator set to subscript separat +or. print FOUT "@$_" foreach (@LoL); close FOUT; } my @newLoL; { #block for localizing open FIN, "<./datafile"; push (@newLoL, [split m/$;/]) while (<FIN>); close FIN; } print Dumper(\@LoL, \@newLoL);

    As long as you don't want space efficiency, memory efficiency, power, or binary data, that way is blazingly fast. =P The field separator in your file will be "\034" and the record separator would be "\n" so those two chracters are verboten in the data.

    Useless triva for you, chracters \034-\037, the ones between the ESC and the SPACE chracters were once for data separation. Perl (thanks to AWK) uses \034 aka "FS" as its field separator. This is in fact a horrendous error since the original meaning of the chracters is: File, Group, Record, and Unit Separator. We really "should" be using the Unit separator "\037" for breaking up fields but so many people do it wrong that it isn't worth the fight.

    --
    $you = new YOU;
    honk() if $you->love(perl)

Re: (tye)Re: HOW TO CREATE A DATABASE FILE WITH FIELDS IN RECORDS
by ichimunki (Priest) on Dec 27, 2000 at 08:56 UTC
    I was using the words pack and unpack without regard for their Perl meanings, and then realized I might as well link them as one of the many ways Perl makes it easy to fetch and store data. I don't recommend using any Perl function or Perl itself for the heavy lifting part of database development. Although by carefully crafting your own indexes, and storing your data in fairly discrete, delimited text files, you can easily put together a relatively simple system, but it won't have near the flexibility that using Perl in conjunction with some other package would.