Back in the days when I didn't have access to databases, I used to write everything to flatfiles. This sub opens a delimited CSV file and takes the column names from the first line (which gets choped off) then it rolls through using the 1st row as a "primary key".
An example of what a database file might be (tab delimited):
PEOPLE CARS CAR_COLORS AGES
John Volks avocado 26
Mira Fiat (yuck) black 25
Mom Twingo cherry 50
I haven't used it for a long time, but maybe someone has comments or even has a use for it...
my @columns = OpenFlatFile('TEST')
or warn('file missing, unaccessible or empty');
foreach (keys %{$columns[0]}) {
# might as well have said 'keys %PEOPLE'
print "$PEOPLE{$_} drives a $CAR_COLORS{$_} $CARS{$_} and is $AGES{$
+_} years old.\n"
}
sub OpenFlatFile {
my ($datfile) = $_[0];
my $delimiter = "\t";
my $val;
open(FILE,$datfile) or return(0);
my @tmp = <FILE>;
close(FILE);
my $head = shift(@tmp);
chop $head;
@{$datfile} = split($delimiter,$head);
foreach (@tmp) {
my $x = 0;
chop;
my @line = split($delimiter,$_);
foreach $val (@{$datfile}) {
if ((! defined ${$val}{$line[0]}) &&
($line[$x] ne '')) {
${$val}{$line[0]} = $line[$x];
}
++$x;
}
}
return(@{$datfile});
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.