"it_says_BALLS_on_your forehead" <> wrote:
>
> hmm, i thought (perhaps this is a misapprehension on my part--i will
> investigate) that:
>
> for (@data)
>
> ...automatically 'lexified' $_.
It automatically localizes it, which is quite different. If it lexified
it, then only things within the foreach block's lexical scope could stomp
on $_. But because it localizes it, anything within the foreach's dynamic
scope can stomp on it. Because of your use of modules and callbacks, there
is a lot of invisible stuff within the dynamic scope.
This shows the dynamic nature:
$ perl -le 'sub foo {$_="bar"}; foreach (1..10) {foo(); print $_}'
bar
bar
bar
....
> > > do i need to
> > > stick a continue block around the $pm->finish? i understand that if i
> > > do this, the parent will also call finish, but this will be a silent
> > > no-op when called by the parent.
> >
> > I don't think that that is the problem, but why not do it anyway?
> >
>
> i'm not too comfortable with continues. i've read that they aren't used
> much in real-life code. is the use of continue blocks indicative of a
> wrong way of thinking?
I very rarely use continue blocks myself, but when I see someoneelse's code
with a well-placed continue I always think to myself that that saved a lot
of messy code, and that I should remember to use them more often.
The one thing, other than failure to think of it, that does stop me from
using them more often is their lexical isolation from the main loop block.
foreach my $foo (@foo) {
##...
my $bar=something();
##...
next if something_else();
##..
} continue {
##D'oh
##Can't access $bar here
}
Anyway, they probably aren't all that rare.
#sorry about the wrap
~/perl_misc]$ find /usr/lib/perl5/ -name "*.pm" -exec perl -lne 'print
"$ARGV\t$_" if /continue\s*{/' {} \;
/usr/lib/perl5/5.8.0/File/Find.pm continue {
/usr/lib/perl5/5.8.0/File/Find.pm continue {
/usr/lib/perl5/5.8.0/ExtUtils/MakeMaker.pm } continue {
/usr/lib/perl5/5.8.0/ExtUtils/MM_MacOS.pm } continue {
/usr/lib/perl5/5.8.0/ExtUtils/MM_Unix.pm } continue {
....
> should i re-design my code so that it is not
> necessary?
Um, it already isn't necessary. As far as I can tell, the only reason
one *might* erroneously think it is necessary is if you tried to
conditionally "next" out of the run_on_finish code, which you thankfully
aren't trying to do. That would be a bad thing to do in general, even if
not using ForkManager. You are supposed to "return" out of subroutines,
or just let them finish naturally, not "next" out of them. If you use
warnings, you will get warnings when you do such uncouth things.
Put since you are using ForkManager, the "next" in the subroutine would not
only be bad manners, it would also be highly broken. The run_on_finish
coderef is called from within the parent, not the child (otherwise, pushing
the token back on the stack would have no effect, the useful stack lives in
the parent, not the child). If the the run_on_finish code invokes "next",
it is the parent that will suffer this invocation. And who knows what
havoc that will wreak.
Xho
--
--------------------
http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB