this script opens a data file counts the amount of lines if data file reach 15 lines then the script deletes all lines.
i am not sure if it useful for anyone but it is to me ...
NOW i have one question and i cant find the answer so i hope some one can help me out ..
My question; the scripts deletes all lines if reach 15 lines... 15 = $cleanlist
but if data file contains 16 lines script do nothing
how can i say run &clean if is 15 or more ... not just 15 15 and plus or if $cleanlist or more ..
how do you write that?
i cant find it as i dont know for what to search in book or www
ps: if you run clean.cgi then it prints amount of lines
if you run clean.cgi?clean then it will remove all lines.
if you run clean.cgi and data file contains 15 lines then script auto delete all lines.
* What i want that it auto deletes lines if reach 15 or more ... but more aint working yet ;-(
############
#!/usr/local/bin/perl
$cleanlist = "15";
if ($ENV{'QUERY_STRING'} eq "clean"){ &clean}
open ( FH, "data.txt" ) ¦¦ die "Couldn't open that file\n";
while ( <FH> ) {
$count++;
}
print "Content-type: text/html\n\n";
print " file contains $count lines\n";
if ($count eq "$cleanlist"){ &clean}
sub clean {
open(FILE, "> data.txt") or die " Cant open data.txt: $!";
print FILE "";
close(FILE);
}
#################
God i love perl ...
this script is only 15 lines and it has to me 3 powerfull functions. count lines, clean lines and auto clean lines .. ;-) The world is probally spinning around powered by a perl script as well ehehehe .. with a cron job for day a nd night ...
if ($count >= $cleanlist){ &clean}
instead of
if ($count eq "$cleanlist"){ &clean}
And also, when you're defining $cleanlist, it's better to do it without quotes as it's a numeric datatype you're defining (although perl is pretty forgiving about datatypes, it's better to be safe).