On Sat, Mar 15, 2003 at 10:53:53AM -0500, Andrew Pimlott wrote:
> On Fri, Mar 14, 2003 at 09:59:42PM -0500, Uri Guttman wrote:
> > well, this is what will be supported which is named nested subs.
> > it looks to be compiled but callable only from within the outer sub and
> > it has access to the outer subs vars.
> >
> > my $c;
> > sub foo() {
> > my $a;
> > my $b;
> >
> > my sub bar() {
> > $b = $a + $c;
> > }
> >
> > bar();
> > }
> >
> > is that close enough?
>
> I think it's absolutely fine, assuming that &bar is a real closure
> that can be returned or passed to other functions. I think nested
> subs should default to "my", since there's no other point in using
> them, but if Larry likes the "my", it can stay.
I agree with your preference, but I wish it worked without the "my".
See Apache::Registry. (I hope that's the one I mean.) It packages a
whole CGI script in a sub by textually inserting it in "sub {" "}".
This trick would be quite useful if not for the "will not stay shared"
issue, aka the "all named subs are global" problem.
See Scheme do it right:
http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-8.html#%_sec_5.2.2
Personally, I would never intentionally write a nested sub in current
versions of Perl. Apart from having global subs pasted into an outer
block by something like Apache::Registry, what good does the current
nested sub feature do? Of course, some code somewhere relies on them
being global, but not Apache::Registry, which I believe also pastes a
generated package declaration around its scripts in order to defeat
the global-ness.
Share and share alike! :~)
--
John Tobey <[EMAIL PROTECTED]>
\____^-^
/\ /\
_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm