laziness, impatience, and hubris | |
PerlMonks |
modifying perl functions without having to write own functions...by argv (Pilgrim) |
on Dec 23, 2006 at 18:06 UTC ( [id://591466]=perlquestion: print w/replies, xml ) | Need Help?? |
argv has asked for the wisdom of the Perl Monks concerning the following question:
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:
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.
Dan Heller http://www.danheller.com
Back to
Seekers of Perl Wisdom
|
|