This script is intended to see if a file in a list is linked toin an HTML file and if the file is not linked to it should be deleted. This works great until I do the unlinking bit. If I just print out the list of files to be deleted it gets it right every time. But this snippet<br
while (@delete_me) { $x = pop(@delete_me); unlink $x or die "Can't unlink $x : $!"; }

produces this errorCan't unlink /home/mysite/www/clean_up/pages/ghost.html : No such file or directory at clean_up.pl line 43.
despite the fact that the path is full and accurate.
Any help?
TIA
jg
#!/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; }
_____________________________________________________
If it gets a little bit out of hand sometimes, don't let it fool you into thinkin' you don't care.TvZ

In reply to File Not Found in Attempt To Unlink by jerrygarciuh

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.