Multi Line string in flat file DB
You could seperate each entry by a |. Than when you need to use the database, just get the contents of the database and split it up.
Somthing like this
code:
local $/; open(IN,"<file.here"); $database=<IN>; while($database =~ m/(.+?)\|/sogi) { $entry = $1 . "<br>"; push(@arr,$entry); } Now each entry is an element in the array @arr. [/code] See the previous code working at http://dlo.net/~rob/cgi-bin/textdatabase.cgi the text file can be viewed at http://dlo.net/~rob/cgi-bin/textdatabase.txt Hope that helps.. ------------------ Due to precipitation, for a few weeks K2 is bigger than Mount Everest.
http://www.thehungersite.com - http://www.therainforestsite.com
http://www.ratemymullet.com - Beauty is only mullet deep.
Malte posted this at 16:25 — 2nd February 2000.
They have: 297 posts
Joined: Apr 1999
Hey,
whats the best way to save a multi line string in a flat file database.
Do you have to do something like:
s/+(\n)/%linebreak%/g
and then undo the process when reading the file or what would work better?
Thanks,
Malte
japhy posted this at 22:57 — 2nd February 2000.
They have: 161 posts
Joined: Dec 1999
You can use a line (or record) delimiter other than "\n" in your database. The popular fortune program, for instance, uses %% between its "records". Here's a sample implementation:
Malte posted this at 23:06 — 2nd February 2000.
They have: 297 posts
Joined: Apr 1999
Would this work for a database which contains more than one multi-line string in multiple rows and columns?
Malte
Malte posted this at 22:41 — 3rd February 2000.
They have: 297 posts
Joined: Apr 1999
Japhy, I read your article about this on your homepage, so everything is fine.
Thanks,
Malte
japhy posted this at 03:02 — 4th February 2000.
They have: 161 posts
Joined: Dec 1999
Ah, cool Malte. Check out the PerlMonth.com web site -- that's where that column is.
I'm thinking of writing an article specifically on modifying the way data is input and output with the $/, $\, $", and $, variables. Tentative title would be "Funking it Up with the Punctuation Variables" -- but something makes me think that'll have to be changed.
------------------
--
MIDN 4/C PINYAN, NROTCURPI, US Naval Reserve
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.