James Mastros wrote:
> OTOH, for functions that look more like {startup;
> compute; teardown}, magic-varable is nice. Think of the functions where you
> have a varable named $ret or somesuch, and you compute it, have another few
> lines or few screens of code, and then say "return $ret".
I see this all the time. What would fit the bill is to have something
like a C<continue> block for subs; they get called during the same
phase as destructors of objects going out of scope.
sub readit {
open F, "< $f" or die "$f: $!"; # even in the tiniest example
my $l = <F>;
close F;
$l
}
becomes
sub readit {
open F, "< $f" ...
scalar(<F>)
}
continue {
close F;
}
O.k., the example is a little bogus, what with IO::File etc.
But for the general case...
> the best I can offer is two magic values, $^R and @^R. And, as
> sombodyoranother pointed out, @^R can't be a real array, only a list. (I
> don't think that will be a problem, though.)
I think it would be a huge problem. Unless, of course, we don't
mind adding a new fatal error:
% perl -we 'push @^R, 42'
Type of arg 1 to push must be array (not list alias) at -e line 1, at EOF
Execution of -e aborted due to compilation errors.
--
John Porter
Ann wenno haddum billizac...