[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Deleting a file



Lars G. Skjellerup wrote:
> 
> I have a small problem. I don't seem to be able to use this to
> delete a file:
> 

> [...]

>     ## if I print $pic it contains the right path and filename
> 
>     ## I can't find out if it is the open(), unlink or $pic
>     ## that is the problem.

Yes you can, you just haven't tried.

>     open(TFH, $pic);

open(TFH, $pic) or die "Can't open '$pic': $!\n";

>     unlink TFH;

unlink TFH or die "Can't unlink '$pic': $!\n";

>     close(TFH);

close(TFH) or die "Can't close '$pic': $!\n";


If you don't ask for error reports, you'll never know what went wrong.


Anyway, there are two problems here.

First, one unlinks files, not filehandles.
unlink($pic) or die "Can't unlink '$pic': $!\n";

Second, files are opened for reading and/or writing; there's no 'unlink'
mode when opening a file.  :)
In other words, don't open the file, don't close it, just unlink it!


Ronald


===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org