Re: Handling errors when working with files
- From: racsolig@xxxxxxxxx (Oscar Gil)
- Date: Mon, 31 Dec 2007 02:13:05 -0800 (PST)
Thanks Tom, it helped. :-)
I learned some more few things. ;-)
Regards,
Tom Phoenix <tom@xxxxxxxxxxxxxx> wrote:
On Dec 30, 2007 10:17 AM, oscar gil 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: beginners-unsubscribe@xxxxxxxx
For additional commands, e-mail: beginners-help@xxxxxxxx
http://learn.perl.org/
---------------------------------
Never miss a thing. Make Yahoo your homepage.
- References:
- Re: Handling errors when working with files
- From: Tom Phoenix
- Re: Handling errors when working with files
- Prev by Date: Different way of getting Standard input
- Next by Date: Re: Different way of getting Standard input
- Previous by thread: Re: Handling errors when working with files
- Next by thread: export variables
- Index(es):
Relevant Pages
|
|