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: