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

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.