Re: yoda 2
[email protected] (Tony Olekshy) Wed, 16 Aug 2000 21:15:54 -0600
| Newsgroups | perl.perl6.language.errors |
|---|---|
| Organization | Avra Software Lab Inc. |
| Message-ID | <[email protected]> |
"David L. Nicol" wrote:
>
> sub openrecord{
> my $RecordFileName = &GetRecordFileName;
> TRYOPEN:
> open REC, "$RecordFileName" or throw "FILE-NO-OPEN";
> #work with the file
> ...
>
> return;
>
> my $problemcounter;
> catch "FILE-NO-OPEN"{
>
> $problemcounter++ > 5 and return undef;
> $RecordFileName = &GetRecordFileName;
> goto TRYOPEN;
> };
> };
>
> The above is [a lot] cleaner than the same thing done with eval/die;
Hmm, with eval/die...
sub openrecord
{
for (my $attempt = 0; $attempt < 5; ++$attempt) {
my $fileName = &GetRecordFileName;
eval { open REC, $fileName; };
if ($@) {
if ($@->isa("FILE-NO-OPEN")) { next; }
die $@;
}
# Work with the file...
return;
}
return undef;
}
Or, with try/catch...
sub openrecord
{
for (my $attempt = 0; $attempt < 5; ++$attempt) {
my $fileName = &GetRecordFileName;
try { open REC, $fileName; }
catch "FILE-NO-OPEN" { next; }
# Work with the file...
return;
}
return undef;
}
Yours, &c, Tony Olekshy