Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: overriding print built-in

by m.att (Pilgrim)
on Apr 12, 2006 at 01:35 UTC ( #542727=note: print w/ replies, xml ) Need Help??


in reply to overriding print built-in

As per the last line in the section of perlsub entitled 'Overriding Built-in Functions':

Finally, some built-ins (e.g. "exists" or "grep") can't be overridden.

The reason being that some builtins cannot be reliably emulated via prototypes. print is one of those functions. You can tell which functions you can indeed override with the prototype function:

print prototype CORE::print;

Prints nothing. Also, from perldoc -f prototype:

If FUNCTION is a string starting with "CORE::", the rest is taken as a name for Perl builtin.  If the builtin is not over-ridable (such as "qw//") or its arguments cannot be expressed by a prototype (such as "system") returns "undef" because the builtin does not really behave like a Perl function.

The specific issue with print is that you can't express the optional filehandle target. (eg: print FH "foo";)

Hope that helps.

m.att

** added reasoning behind print not being overrideable.


Comment on Re: overriding print built-in
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://542727]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2014-08-30 11:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (293 votes), past polls