jerrygarciuh has asked for the wisdom of the Perl Monks concerning the following question:
while (@delete_me) { $x = pop(@delete_me); unlink $x or die "Can't unlink $x : $!"; }
_____________________________________________________#!/usr/local/bin/perl -w use strict; use Fcntl ':flock'; use CGI qw/:standard/; use CGI::Carp qw/fatalsToBrowser /; my $base_path="/home/mysite/www/clean_up"; my $search_terms_file="$base_path/terms.txt"; my $file_to_search="$base_path/searchme.html"; my ($term,$results,@delete_me, $x); do_the_clean_up(); sub do_the_clean_up { open (ST,"$search_terms_file") or die "where's the search_terms fi +le? : $!"; flock (ST,LOCK_EX) or die "Couldn't flock search_terms: $!"; my @search_terms = <ST>; flock(ST,LOCK_UN); close ST or die "search_terms won't close : $!"; chomp (@search_terms); open (FTS,"$file_to_search") or die "where's the file_to_search? : + $!"; flock (FTS,LOCK_EX) or die "Couldn't flock file_to_search.: $!"; my @file = <FTS>; foreach $term(@search_terms) { if ( !grep { /$term/ } @file ) { $term="$base_path$term"; push (@delete_me,$term); } } flock(FTS,LOCK_UN); close FTS or die "Couldn't close file_to_search. : $!"; my @file_list = @delete_me; while (@delete_me) { $x = pop(@delete_me); unlink $x or die "Can't unlink $x : $!"; } print "Content-type: text/html\n\n"; print "<h1>Deleted Files</h1>"; foreach $_(@file_list) { print "$_ <br>"; } exit; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: File Not Found in Attempt To Unlink
by BeernuT (Pilgrim) on Feb 07, 2002 at 02:07 UTC | |
|
Re: File Not Found in Attempt To Unlink
by jerrygarciuh (Curate) on Feb 07, 2002 at 03:11 UTC | |
|
Re: File Not Found in Attempt To Unlink
by jjohn (Beadle) on Feb 07, 2002 at 03:18 UTC |