![]() |
|
Think about Loose Coupling | |
PerlMonks |
RE (2): Filehandle Filterby tilly (Archbishop) |
on Aug 11, 2000 at 05:23 UTC ( #27432=note: print w/replies, xml ) | Need Help?? |
Well since you beat me to the original, here is an
implementation that by default does what btrott's original
display did, but can do anything you want. For giggles and
grins I have implemented new and PRINTF using two different
idioms:
(And yes, chip this is for you because of RE: RE: Shot myself in the foot with a pos. Who said that goto was useless? :-)
EDIT
EDIT 2 Note that this could be more compact still. For instance the anon sub could be made even shorter by removing the temporary variable. But that would not optimize my ability to understand my code. :-)
EDIT 3 For those who do not understand tie, this package has two distinct interfaces. The OO one works like this: The tied interface like this: The apparently shocking similarity in the implementations drives home the fact that tie is nothing more than syntactic sugar to allow you to think about an object which happens to provide the right methods as a native Perl datatype. :-) BTW my absolutely favorite part of this code is the DESTROY method. Stuff like that is what makes Perl great! :-)
In Section
Snippets Section
|
|