Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Flat Database: Outdated Info Removal

by lisaw (Beadle)
on Nov 14, 2002 at 22:22 UTC ( [id://213034]=note: print w/replies, xml ) Need Help??


in reply to Flat Database: Outdated Info Removal

I figured it out on my own, using the following code: REVISED CODE
open(DATAFILEIN,"$catagory.dat") || print "This section is + currently empty...Please check back often!"; print "<table border=0 cellpadding=0 border=0>"; flock (DATAFILEIN, 2); while(<DATAFILEIN>) { chomp $_; @line_pair = split(/=/,$_); $company_name = $line_pair[1]; $time = $line_pair[0]; $email= $line_pair[2]; $member1= $line_pair[3]; $member1phone= $line_pair[4]; $data= $line_pair[5]; $time2 = $line_pair[6]; $data = &stripBadHtml($data); $password= $line_pair[8]; $pictureurl= $line_pair[7]; $website= $line_pair[9]; $member2= $line_pair[10]; $member2phone= $line_pair[11]; $address= $line_pair[12]; $citystatezip= $line_pair[13]; $fax= $line_pair[14]; $catlisting= $line_pair[15]; $currenttime = time (); $difference = $currenttime - $time2; #computing the number of seconds before it expires $expires = $expire_after_days * 86400; if($difference < $expires){ push (@temp,$_); } } flock (DATAFILEIN, 8); if (open(DATAFILEOUT, ">$catagory.dat") ) { flock (DATAFILEOUT, 2); print DATAFILEOUT @temp; flock (DATAFILEOUT, 8); } open(DATAFILEIN,"$catagory.dat") || print "This section is + currently empty...Please check back often!"; print "<table border=0 cellpadding=0 border=0>"; while (<DATAFILEIN>) { chomp $_; @line_pair = split(/=/,$_); $company_name = $line_pair[1]; $time = $line_pair[0]; $email= $line_pair[2]; $member1= $line_pair[3]; $member1phone= $line_pair[4]; $data= $line_pair[5]; $time2 = $line_pair[6]; $data = &stripBadHtml($data); $password= $line_pair[8]; $pictureurl= $line_pair[7]; $website= $line_pair[9]; $member2= $line_pair[10]; $member2phone= $line_pair[11]; $address= $line_pair[12]; $citystatezip= $line_pair[13]; $fax= $line_pair[14]; $catlisting= $line_pair[15];
This works great...but if someone else has a better solution please let me know.

Replies are listed 'Best First'.
Re: Re: Flat Database: Outdated Info Removal
by jdporter (Paladin) on Nov 15, 2002 at 05:13 UTC
    lisaw, if you're not going to follow no_slogan's excellent advice, then I strongly urge you to replace your flock(8) calls with close. Unlocking doesn't close, but closing unlocks. By leaving the file open but unlocked, you put the file at risk.

    jdporter
    ...porque es dificil estar guapo y blanco.

Re: Re: Flat Database: Outdated Info Removal
by admiraln (Acolyte) on Nov 15, 2002 at 16:28 UTC
    In the quest of a better solution I would just offer to bang out a few dents to make thing look better.

    Your code that assign field values to individule vars is very hard on the eyes and could be difficult to debug if you get one of those index wrong. This is compounded by the list being out of order (1 before 0) and the subroutine call hidden in the batch.

    If you would keep this code tab it out so all the "=" and "$line_pair[]" are aligned. Either do the sub call right after the variable assignment and put some blank lines around it or just do after the whole transfer block.

    On the other hand if you don't need to do the transfer at all, all the better. If all that you do is a straight display of the vars in the same order they are in the file then you don't need to transfer them.

    If you need to manipulate a few of them them then create named indexes like (put near the top of your file)

    # indexes to $line_pair $i_data = 5; #add more here if needed.
    and then call the sub this way
    $line_pair[$i_data] = &stripBadHtml($line_pair[$i_data]);
    although this line is more complex there is only one of them, not 15. Also, without the transfer( it may still be needed if you are get the vars off an HTML form) the output line could go from:
    print DATAFILEOUT "$time=$company_name=$email=$member1=$member +1phone=$data=$expiretime=$pictureurl=$password=$website=$member2=$mem +ber2phone=$address=$citystatezip=$fax=$catlisting\n"
    to
    print DATAFILEOUT join("=",@list_pair),"\n";
    In general code should not be hard to look at or look like it was hard to type in. Someone will have to look back at the code again sometimes and it is good practice to make code clear for the next programmer to look at it.

    Remeber that next programmer may be you. Disclaimer

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://213034]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (7)
As of 2024-03-28 10:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found