April 12th, 2000, 02:21 PM
-
Hello,
I am attempting to create a message-board type script. Is there a way a script can save messages (like in a board), without using a database (like mySQL)?
Thanks!
yoshi http://www.datera.com
Comments on this post
April 13th, 2000, 12:40 AM
-
Hi,
probably you may save your messages in a flat file.That is the easy way to save the messages with out a database.
------------------
SR -
shiju.dreamcenter.net
April 13th, 2000, 07:23 PM
-
Thanks.. could you describe to me how placing data into a text file is done, and how to read from it?
yoshi http://www.datera.com
April 14th, 2000, 07:20 AM
-
Hello yoshi,
just i write a very small example for flatfile.here i am adding 3 field values in to the database.
fields are separated by "|" deliminator.
modify this code according to your requirment.
#!/usr/bin/perl
$firstname="Shiju";
$lastname="Thomas";
$msg="messgae goes here";
$database="database.txt";
#flatfile name
#####--- Add a record to the flatfile -###
$record=join("|",$firstname,$lastname,$msg);
#using join for putting "|" deliminator between the fields.
unless(-e $database){
#check whether database is existing or not
#if not existing then,create and add a record to it
open(DB,">$database") | | die "Error creating database $!n";
#open the database
}else{
#database is already their.
#append the records to existing database.
open(DB,">>$database") | | die "Error opening database $!n";
}
print DB "$recordn";
#print the records to the flatfile.
close(DB);
print "Record Addedn";
##########- Reading from the flatfile-#############
open(DB,$database) | | die "opening the database $!n";
#open database for reading the data from it.
while(<DB> ){
#use a while loop for reading whole data from the
#database.
#assain all record to an array
@data=<DB>;
}
foreach $data(@data){
#read from the array
#remove "|" deliminator and separate the field
($firstname,$lastname,$msg)=split(/|/,$data);
print "First Name: $firstnamen";
print "Last Name: $lastnamen";
print "Message : $msgn";
}
close(DB);
tell me if u have any problem with this..
Good Luck!!
------------------
SR -
shiju.dreamcenter.net