I've found there are more cases where I'd like chomp to return something other than "the number of bytes chomped off the end" of EXPR. Of course, making any changes to existing documented behavior would require incompatibilities, but I was wondering if there are ways to *efficiently* introduce extensions to existing behavior without having to change the actual source code. That is, I don't want to have to write a new function that does the modified behavior since it wouldn't be "more efficient" than just writing the mod in-place.
My example is below, where I coerce chomp to return the EXPR it acted upon:
open FILE, "list-of-emails-one-per-line.txt";
@emails{(array) chomp <FILE>} = (); # %emails is now a hash where each
+ key is an email address
close FILE;
So, I'd like to add this "coercing" behavior without having to write a new special-case chomp function. A similar thing would be to extend "lc" (et al.) to act on an array as well as a string.
Is this possible, or am I stuck writing my own functions?
UPDATE: Please don't tell me how to solve the specific task illustrated in the example (such as using "chomp (@_ = <FILE>), @_" to simply yield the desired list. That isn't answering the question on whether "extensions" to existing functions are possible.
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.