note
tye
<p>
You've managed to lose another side effect. With your version, I can't use <code>-x _</code> to see if the file that the iterator just handed to me is executable. I'd have to do another [stat] rather than using the results of the [lstat] that Perl so helpfully caches for me.
</p><p>
So you compressed all of the different items from the stack into two stacks that you keep handy using a closure (rather than a more tradition Perl object). I like it.
</p><p>
I agree that the [chdir] side-effect is problematic. Too bad Unix didn't provide an <i>efficient</i> way to save/restore [chdir] context (based on i-node instead of on a path string). I'd make the [chdir] optional with appropriate disclaimers in the documentation but that defeats the purpose of providing a simple example.
</p><p>
I think I'll try this technique on <a href="http://search.cpan.org/src/TYEMQ/FileKGlob/KGlob.pm">File::KGlob</a>::unbrac (well, using a closure would be cheating since those subroutines are still Perl4-compatible code, though). (:
</p><p>
Thanks for the demonstration.
</p>
- [tye]
248935
249078