The problem is that your unlink isn't targeted at the FILE filehandle. It's trying to delete from whereever the script was run, except that it never gets there, because you're opening a directory with a file open command. Use "or die ("File open error:$!");" on the open and I bet it'll die.

You don't have to open files you are trying to delete. See unlink


Update: Let's look at your script line by line:
open(FILE,"/cgi and perl");
Problems:
  1. You didn't test for a die condition.
  2. You are opening a directory for no real reason
  3. What you are trying for is done by opendir and readdir
while(<FILE>){
problems:
  1. This will read FILE line by line (except that it's a directory), and put the line in $_ (which would never be used anyway)
unlink(<*.txt>);
This line alone should do what you want, if the script is run in the directory you want the text files deleted from.

In reply to Re: Unlinking... by swiftone
in thread Unlinking... by damian1301

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.