CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
What Have Done Wrong?

 



yotam_k
Deleted

Mar 1, 2001, 11:46 AM

Post #1 of 4 (1638 views)
What Have Done Wrong? Can't Post

Could SomeOne Please Look At the Attached Program And Please tell Me If He Sees Anything thats looks like An Error In my program .
I Can Activate this program on my server without 500 Internal error but it doesn't delete the files.

Thank you very much !



(This post was edited by yotam_k on Mar 1, 2001, 10:47 AM)


rGeoffrey
User

Mar 1, 2001, 12:53 PM

Post #2 of 4 (1636 views)
Re: What Have Done Wrong? [In reply to] Can't Post

Starting with the silliest thing that can be wrong, are you sure that all the directories you want to delete files in are in the same directory as the script doing the deleting?

And do you really want to play with a directory called 'messsege/' that has three the letter 's' three times in a row?

You have a die statement in there, did it tell you anything after it ran?

Also, the code looked repetitive to me so here is my rewrite...


Code
#!/usr/bin/perl 

$buffer = $ENV{'QUERY_STRING'} ;

print <<endHeAD;
Content-type:text/html

<script>
/*
<body>

</body>
*/
</script>

vbv
endHeAD

###########################################################

open (INN, "id/id.data") ;
my @idfile = <INN> ;
close (INN) ;

my $File_start = "forum1" ;
foreach $id (@idfile) {
my $BoxQQ = (split (/\|/, $id))[0] ;
$FileEnd2 = "-$BoxQQ.data" ;

&deleteFiles ("forums/allmessges/$File_start", 'messsege/', $FileEnd2);
&deleteFiles ("forums/links/links", 'links/', $FileEnd2);
&deleteFiles ("forums/replays/replays", 'forums/replays/', $FileEnd2);
&deleteFiles ("forums/$File_start", 'messsege_files/', $FileEnd2);

my $file = "data/counters/counter$FileEnd2";
unlink $file or die "Couldn't Delete File '$file' because: $!\n";
$count++;
}

###########################################################

sub deleteFiles {
my ($listfile, $prefix, $suffix) = @_;

open (DATA, "$listfile$suffix") ;
my @files = "$listfile$suffix", (map { $prefix . (split (/\|/, $_))[0] . $suffix } <DATA>) ;
close (DATA) ;

foreach (@files) {
unlink $_ or die "Couldn't Delete File '$_' because: $!\n";
}
}

Each time you split a line you only want the first element, so I put a ( )[0] around the split statements to only get the one element we care about.

And the bulk of the work is pushed into &deleteFiles with will read a datafile, then use it to make a list of files to delete and will also delete the datafile. Except for "data/counters/counter$FileEnd2" which is still treated differently.

I also moved the semicolon on the print statement to be on the same line as print, not at the end as that is how I have always seen it and it makes me feel better.

Not having directories of stuff to delete I have not tested this, but it should work if I was wrong with my first two suggestions.

--
Sun Sep 9, 2001 - 1:46:40 GMT, a very special second in the epoch. How will you celebrate?


yotam_k
Deleted

Mar 1, 2001, 1:17 PM

Post #3 of 4 (1635 views)
Re: What Have Done Wrong? [In reply to] Can't Post

First Of all Thanks you very much for the great help and the effort you made .
The first two advices weren't the case 'couse I'v tested it 2000 times .
and the die doesn't says anything.

But your correction seems to be very nice , I'll test i't now and i'll tell you if it worked .

Again thank you.

Yotam




yotam_k
Deleted

Mar 1, 2001, 1:24 PM

Post #4 of 4 (1635 views)
Re: What Have Done Wrong? [In reply to] Can't Post

Hay Again , well listen , I cant copy the program you have written from the page .
please attach It to a reply messege
Could you?



 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives