A pretty common example of a use of anonymous subroutines
is the File::Find module:
use File::Find;
find(\&wanted, @directories_to_search);
sub wanted { ... }
What File::Find does for you is to descend through one or more trees of directories, and it runs some user defined code at each point through the tree. So the author designed around the idea of passing in a code reference to an arbitrary routine which can you can call anything you want.
In this example it's "wanted", in another application it might be "unlink_big_files".
(There's a strong argument that this File::Find interface was a bad idea, and it has a number of competitors these days like File::Find::Rule, but still if you're working on existing code, you're likely to see File::Find used.)
Maybe you should try and give us a better idea of what you
don't get about anonymous subs...
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.