"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