in reply to use strict;,$main::, and AUTOLOAD: Why can't we all get along?
Again it depends. AUTOLOAD is more for use with object oriented programming; and indeed again strict will not complain if you call a sub as main->$subname($_). Of course the first parameter passed is now the classname, "main" in this case, and your subs will have to accomodate for that, by shifting it off first thing or however you choose to handle it.
I am slightly irked by the setup as displayed; coderef() is a rather unhelpful name and the distribution of decision making is a bit clumsy IMHO. I'd do something like this:
sub default_handler { print OUT "@@@ main::$_[0](\$tree) @@@\n"; recurse($_[1]); } sub dispatch { ref $_[0] eq 'ARRAY' ? \&startrule : $main::{$_[0]} || \&default_handler; } sub startrule { my $tree = shift; ref eq 'ARRAY' and dispatch($_->[0])->($_) foreach @$tree; }
I'm not happy with that either though.. I think a clean solution would require a dispatch mechanism separate from Perl's that does not rely on sub names. No propositions however as right now my brain won't cooperate.
Also I'm wondering why there are too many locations for tadman's pragma solution to be feasible? After all, you have to add the coderef() call to the same places that you'd have to add no strict 'refs'; to, unless I'm missing something important.
Quick note with regard to your snippets: you are aware that @$_[0] is actually a single element array slice? Since you want a scalar, you should write that as $$_[0] or $_->[0].Makeshifts last the longest.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: use strict;,$main::, and AUTOLOAD: Why can't we all get along?
by hsmyers (Canon) on Jul 18, 2002 at 13:29 UTC | |
by Aristotle (Chancellor) on Jul 18, 2002 at 17:12 UTC |