Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Tacking a function on to STDOUT?

by larryk (Friar)
on May 28, 2001 at 15:11 UTC ( [id://83718]=note: print w/replies, xml ) Need Help??


in reply to Tacking a function on to STDOUT?

I thought you might be able to do...
#!perl -w use strict; sub my_print(@) { my @stuff = @_; print STDOUT time,": @stuff\n"; } *print = *my_print; print "Hello World!";
but you can't so don't listen to me.

the warning message isn't useful in this case but if I change it to &print = &my_print; it prints...

Can't modify non-lvalue subroutine call at C:\Perl\scripts\newprint.pl + line 8. 991047768:
so it reckons I can't do it but it has printed the time and the newline from the function just without the @_.

can this be made to work?

larryk

"Argument is futile - you will be ignorralated!"

Replies are listed 'Best First'.
Re: Re: Tacking a function on to STDOUT?
by RhetTbull (Curate) on May 28, 2001 at 18:39 UTC
    Certain perl built-ins can be overriden and others can't. For a discussion on this, see this node. The following code shows one way to override a built-in:

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-24 18:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found