#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2000
    Posts
    108
    Rep Power
    15
    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

    • Gran Roguismo agrees
  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    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
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2000
    Posts
    108
    Rep Power
    15
    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
  6. #4
  7. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    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

IMN logo majestic logo threadwatch logo seochat tools logo