You might want to not use the Function package that way. Better would be to put your code refs in a hash. Then you can just eval the hash value, instead of using $ref->(). That's very bad to do when $ref is being set by input! Also, why are you adding functions that have to already be in the namespace? They're already there, you don't add them to anything, just call them. What I use for something similiar is an array of hashes, the hashes containing name, regex, and code entries. Then I can loop through the array, test each regex against the input, and execute the code if it matches. Also, I can just add a hash ref to plug in a function, no need to mess with the namespace at runtime.
But that is all that is gained by all that, being able to plug in extra parsers without restarting. Usually that's not needed... I usually only do it in the case of network bots that have to interact with users. Generally, it's best to just stick to the exact methodologies used in the "perltoot" Perl documentation. If you don't see it in there, it's probably a sign to rethink the implementation.
Another important thing is, I don't see a use strict or a use warnings. Probably you just trimmed that part to make your post concise, but you need to include those so we know that you're not just digging holes for yourself. Without strict mode and warnings, there is no salvation.
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.