my $testit = exec "cd work/ ;tar xf $files ; cd ..";
if ($testit == undef)
Some problems here:
- exec will typically not return, as it replaces the current program by another. Use system instead.
- system will return whether the command ran successfully, but in the case of having separate statements, it will return the success of the last statement - the cd. Its return value is not something you are interested in - furthermore, there's no point of doing cd .. at the end. The command is running as a separate process, and changing its working directory at the end is pointless. Also, you'll do the tar even if the first cd fails. You could do: cd work && tar xf $files, which will only run the tar if the cd succeeds.
- If a shell command runs successfully, false is returned - a true value indicates a failure of some kind. This might seem counterintuitive, but since there's only one false number (0), and many true numbers, and there are many reasons a command can fail, this has some merit.
- Don't compare your variable with undef. If you want to check for definedness, use defined $variable. But in this case, just check for truthness.
Abigail