Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

delete file

by persianswallow (Novice)
on Aug 01, 2011 at 10:16 UTC ( #917799=perlquestion: print w/ replies, xml ) Need Help??
persianswallow has asked for the wisdom of the Perl Monks concerning the following question:

Hi,i have written following code to delete files that produce between running program after use,but it doesn't work.please help me

@files = ("domainlist","result","tmp"); foreach $file (@files) { unlink($file); }

Comment on delete file
Download Code
Re: delete file
by Corion (Pope) on Aug 01, 2011 at 10:22 UTC

    Have you looked at what $! contains? Also, are the files still held open?

    for my $file (@files) { unlink $file or warn "Couldn't remove '$file': $!"; };

    Maybe the path to these files is not valid anymore because you changed the current directory?

    Also see File::Temp for creating and managing tempfiles.

Re: delete file
by moritz (Cardinal) on Aug 01, 2011 at 10:26 UTC
Re: delete file
by bart (Canon) on Aug 01, 2011 at 11:15 UTC
    If you are on Windows, you have to close the files before you can delete them.

    Also make sure you're in the right directory when you use relative paths.

    And there's no need for a loop, unlink accepts a list of files to delete as arguments.

Re: delete file
by dreadpiratepeter (Priest) on Aug 01, 2011 at 11:16 UTC

    When you say "doesn't work" you provide no useful information to us. If you want to get good answers, you need to say specifically what you were expecting to happen and what actually happened. Pasting any error messages would help too.

    This is one of my big pet peeves. I have an entire QA department at work that seem to think that "doesn't work" is an acceptable bug report. makes me nuts



    -pete
    "Worry is like a rocking chair. It gives you something to do, but it doesn't get you anywhere."

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://917799]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (16)
As of 2014-04-16 17:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (433 votes), past polls