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

Re^2: replacing say function

by d5e5 (Beadle)
on Feb 11, 2011 at 21:54 UTC ( #887688=note: print w/replies, xml ) Need Help??

in reply to Re: replacing say function
in thread replacing say function

I like bart's (edited to correct name) solution except you may want to add a prototype so you can call the sub without parentheses around the arguments.

#!/usr/bin/perl use strict; use warnings; use 5.008; sub say (@){ local $\ = "\n"; print @_ ? @_ : $_; } say 'Hey';
>>>Update>>>: On further testing, I guess you don't need a prototype. The trick is to define the sub above the statement where you call it. The following works just as well for me:
#!/usr/bin/perl use strict; use warnings; use 5.008; sub say{ local $\ = "\n"; print @_ ? @_ : $_; } say 'Hey';

Replies are listed 'Best First'.
Re^3: replacing say function
by bart (Canon) on Feb 11, 2011 at 22:45 UTC
    You don't need a prototype for that. All you need to do is to define the sub before you call it — or put it in a module that you use. Same thing.
Re^3: replacing say function
by cyber-guard (Acolyte) on Feb 13, 2011 at 18:09 UTC
    Sweet! Thanks, all done now :)

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2023-03-29 06:37 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (70 votes). Check out past polls.