in reply to Problem with system ()

Well, system returns zero unless the program completely fails to start when it returns a -1. So, zero would only be returned if successful, meaning that die will be called. You could always call the Perl function chdir instead of calling system, or you could call system like

system("cd C:\temp") == 0 or die "Error!:  $?";

If you choose the chdir route remember that if you want to keep what you have, the "\" character is the escape character, so Perl will interpret this as "C:<tab character>temp". You have two choices. The first is escape the backslash so it will look like

chdir "C:\\temp" or die "ERROR!: $!";

or ActiveState will accept "/" as the directory separator, so you could use

chdir "C:/temp" or die "ERROR!:  $!";

Replies are listed 'Best First'.
Re: Re: Problem with system ()
by Anonymous Monk on Mar 19, 2003 at 14:35 UTC
    All, as ever, many thanks for the responses. I have now fixed the problem. The code I have chosen is as follows:
    chdir "C:\\Program Files\\Analysis\\Auditfiles" or die "ERROR!: $!"; system ("del *.audit");
    I tried to install File::Chdir but unfortunately received a whole load of errors during nmake test that I couldn't fathom. This was a non-starter. Also, I tried using unlink and glob together, but while this compiled, it didn't actually delete anything. I realise chdir is bit crude, but the script I am using it in is very simple. Thanks again!