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

Yes. Perl has the ability to create and store incredibly complex data structures. It has numerous methods for using data on disks, one way or another. And it can certainly store both ascii and binary data in files and pack and unpack this

See perlman:perldata, perlman:perlref and Data::Dumper for some hints as to just how easy it is to build some very complex records and store them to disk. Perl is not a highly optimized DB management system, though-- it is a programming language. But building small (which I suppose is pretty relative) DB packages would be one great way to start with Perl.
  • Comment on Re: HOW TO CREATE A DATABASE FILE WITH FIELDS IN RECORDS

Replies are listed 'Best First'.
(tye)Re: HOW TO CREATE A DATABASE FILE WITH FIELDS IN RECORDS
by tye (Sage) on Dec 27, 2000 at 08:36 UTC

    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")
      "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)

      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.