On Dec 30, 2007 10:17 AM, oscar gil <[EMAIL PROTECTED]> wrote: > What I still don't understand is why $! and $^E are set as there was an > error though there was not :-?.
Those variables may be set when your perl binary internally needs to use a system call or something similar. During or shortly after your program uses open(), for example, perl has to make some several complex system calls, some of which may fail without causing problems at the Perl-programming level. The chief use of those variables is just after certain operations have failed; after a success they may have some irrelevant failure code left over from an unrelated operation. > Tom, How would you handle an error after an acction done on files, > directories and so on?. I'm not sure what you're asking for here. In most cases in Perl code, the thing to do is to write something like "or die" with a good diagnostic string wherever a key step might fail. It's common to need to do some kind of cleanup after a failure; in Perl, that's often done with an eval block, although an END block can also be useful, depending upon the type of cleanup. But for some cases, it's easiest to just use Perl's normal control structures: foreach my $file (@lots_of_file_names) { if (unlink $file) { print "You'll never see '$file' again!\n"; } else { print "Couldn't unlink '$file': $!; continuing..."; } } Hope this helps! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/