Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: deleting a file

by particle (Vicar)
on Jun 04, 2001 at 23:44 UTC ( #85582=note: print w/replies, xml ) Need Help??


in reply to deleting a file

How about something that uses the output of unlink for a good purpose? no sense in letting it go to waste, after all...
@files = qw/file1 file2 file3/; $cnt = unlink(@files); unless( scalar(@files) == $cnt ) { die("Problem unlinking $files[$cnt]! $!"); }
also, this tells you which file was the problem, e.g.
Problem unlinking file2! No such file or directory at del.pl line 4.
there's always a better way. is there something better here?

Update 2002-06-19: yes, there's a better way. the above code assumes too much about the return value from unlink.

you can't reliably determine which file(s) failed to unlink from the return code alone. i suggest the following modification, which will report accurate results:

unless( $cnt == @files ) { die 'Problem unlinking ', $cnt, ' of ', scalar(@files), ' files! ', +$!; }
=Particle

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://85582]
help
Chatterbox?
[ww]: or a lot more than (22*2) for /me
[ww]: er -- senior cognitive deficiency: ((22+(22*2))
[ww]: (but pls don't s/senior/senile/ ... not yet
[karlgoethebier]: A bit more audience now: The Impact of Information Sources on Code Security Very interesting IMHO...
[karlgoethebier]: ..it's about copy & paste ;-)
[ww]: Wonder what IEEE would have thought w/survey based on PM/perl
[ww]: s/thought/found/
[erix]: that title is a broken* sentence, no? But maybe that's deliberate
[karlgoethebier]: ww:My first thought, to be honest...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (10)
As of 2017-09-25 14:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (280 votes). Check out past polls.

    Notices?