in reply to Perl Warning Help

the problem is in the health routine. I am trying to delete a file if it exist with
if (-e $fn) { system("del $fn"); }
$fn is defined as
my $dir = getcwd; my $fn=$dir."\\Logs\\temp.log";
is this a bad way to delete a file if it exists...
i have also change the loop to use new vars so i am not using $x twice, brain fart there...

Replies are listed 'Best First'.
Re^2: Perl Warning Help
by xdg (Monsignor) on Nov 28, 2005 at 16:07 UTC

    Try unlink

    unlink $fn;

    Addendum: Does $fn ever have spaces or forward slashes in it? If so, I'd guess that's what's causing your problems handing it off to system.

    -xdg

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

      that worked....thanks for your help
Re^2: Perl Warning Help
by tirwhan (Abbot) on Nov 28, 2005 at 16:09 UTC

    Well, I don't do Windows, but I'm pretty sure it would be better to use the inbuilt unlink command instead of system.

    if (-e $fn) { unlink $fn or die "Can't remove $fn"; }

    Note that this will not work on directories (use rmdir for that).


    Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -- Brian W. Kernighan