Hello
my programme is stored in ..Server\htdocs\cgi-bin with name glob.pl and is the following
#!/usr/bin/perl -w use warnings; use LWP 5.66; my $browser = LWP::UserAgent->new; $browser -> timeout(900); use CGI qw(:standard); print header, start_html( -title=> 'Page 1' , -bgcolor=>'#eeeeee'), p(h1({-align=>CENTER},'Trial')) ; @files1 = glob ("../Results/*.txt");#collect all the files into an arr +ay foreach my $file (@files1) { print p("s $file"); if ($file=~/(\S+)[\/](\S+)[\/](\S+).*/g) { print p("to $3"); unlink("$3"); if (unlink($3) == 0) { print "$3 deleted."; } else { print "File was not deleted."; } my $FileToWrite = "../Results/"; open (PearsonResult,">>$FileToWrite$3") || die "co +uldn't open the file $!"; print PearsonResult ("test\n "); close PearsonResult || die "can't close:$!"; } } print end_html;
the output when i run it in my browser is nothing. But when i create manually a txt file (with name Test1.txt) on ..Server\htdocs\Result i take as output
s ../Results/Test1.txt
to Test1.txt
Test1.txt deleted.
So i have two questions:
1.why the txt file is not created automated when i run the script from the begging without the need to created manually first and
2.why the txt file is not deleted finally when i run the programme since as i can see throught the glob and the if clause that i use it is stored in the variable $3 the Test1.txt.
When i run it for second time the script i see that it goes to Test1.txt and it writes the word test.But the third time it doesn't delete it and so i find for second time the word test.
Really many thanks in advance for your time.
In reply to Delete txt file in a previous file by stavros
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |