[Melbourne-pm] overloading 'print'
jarich at perltraining.com.au
Thu Mar 16 21:54:32 PST 2006
Mathew Robertson wrote:
> Does anone know how to overload 'print'?
The short answer is that you can't. Print isn't one of Perl's overloadable
functions. (The reason is that the syntax is special cased. You cannot make a
user function with the same prototype.)
The longer answer is that you can... if you use IO::File and its print method.
Then you can just subclass IO::File, and mask the print method to do what you need.
The other non-overridable functions are listed in receipt 12.11 in the Perl
Cookbook (1st Edition). Basically, if the keyword function in toke.c returns a
negative number, then that function can't be overridden.
("`-''-/").___..--''"`-._ | Jacinta Richardson |
`6_ 6 ) `-. ( ).`-.__.`) | Perl Training Australia |
(_Y_.)' ._ ) `._ `. ``-..-' | +61 3 9354 6001 |
_..`--'_..-_/ /--'_.' ,' | contact at perltraining.com.au |
(il),-'' (li),' ((!.-' | www.perltraining.com.au |
More information about the Melbourne-pm