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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.