in reply to Error trapping, and improving code

The system calls will return nonzero if they fail, so a construction like,     (my $res = system @args) and unlink $to_delete; will work. The return value is kept in $res in case you want to do something more about it.

Update: Ok, here's a fancier version

UFILE: while (@files) { #... system @args and do { unlink $to_delete; print LOG "'system @args' failed: ", $?; next UFILE; }; system @other_args and print LOG "'system @other_args' failed: ", $?; #... }

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Re: Error trapping, and improving code
by hiddenlinux (Acolyte) on Jul 05, 2003 at 16:32 UTC
    sorry, i forgot to also add that if an error is found and the file is unlinked, that it shous return to the begining of the script and process the next file.
Re: Re: Error trapping, and improving code
by hiddenlinux (Acolyte) on Jul 06, 2003 at 07:38 UTC
    Thanks Zaxo, where would i put that in my code?
    Also, the code i have seems to run regardless of whether there are any files in the directory or not. Is is trying to process '.' and '..'?