in reply to File::Find considered hard?

It's just that foreach loops are so much more frequently encountered in perl code than passing subroutines.

Beside that, the POD for File::Find introduces the wanted subroutine which creates one more redirection layer in the code and every redirection layer is allways a barriere. Everyone starts with the documentation and what they see is something much more complicated then they think it should be. I believe it would make a big difference if the maintainer changed this to the anonymous subroutine just like in your example.

Replies are listed 'Best First'.
Re: File::Find considered hard?
by jonadab (Parson) on Mar 15, 2004 at 20:50 UTC
    It's just that foreach loops are so much more frequently encountered in perl code than passing subroutines.

    Well, sure, but foreach loops are one of the most common things in Perl. They're probably more common also than while loops or filehandles, but that doesn't make while loops or filehandles hard to understand...

    Beside that, the POD for File::Find introduces the wanted subroutine

    Actually, it's worse than that. The third example in the synopsis passes an anonymous hash using the curly brace anonymous hash constructor, and within that hash one of the values is a reference to a subroutine using \&foo syntax. You need to have at least some grasp of Perl's references to be able to follow this. References are one of the topics a lot of Perl newbies don't get around to for quite a while, because there's quite a bit you can do without needing them. Usually their first need for Perl's references is to construct nested data structures.

    I should disclaim the following statement by noting that File::Find has not been up to this point a module that I've actually used (largely because I have not felt the need for it), but to me, from looking at the docs on CPAN, the interface doesn't look *bad*, though it does look like it requires an understanding of certain Perl concepts that people relatively new to the language might not fully understand yet.


    ;$;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}} split//,".rekcah lreP rehtona tsuJ";$\=$;[-1]->();print