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

Re^2: replacing say function

by d5e5 (Beadle)
on Feb 11, 2011 at 21:54 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-04-25 13:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found