say What?

say

print

bash$ perl -e 'print 235*1.15, "

"'

bash$ perl -E 'say 235*1.15'

-E

-e

say

use 5.10

use feature 'say'

bash$ ssh me@remote "perl -MSomeModule -e 'print SomeModule->VERSION, qq{

}"'

bash$ ssh me@remote "perl -MSomeModule -E 'say SomeModule->VERSION'"

Now that I've got Snow Leopard (finally) installed on my Mac, the default perl binary is now 5.10.0. This means many things: The given keyword and smart matching, the defined-or operator, the wonderful additions to the regex engine, and other things I'm bound to blog about later when I get round to enthusing about them. What I wanted to talk about today is the simpliest change that'll be making the most difference to me on a day to day basis: The "say" keyword. More or lessis exactly the same asbut two characters shorter and automatically adds a newline at the end. This is most useful when you're writing one liners. This quick calculation:Becomes just:(Note the use ofinstead ofto automatically turn on the 5.10 keywords likewithout having to addor.) This saves us a grand total of nine keypresses (including having to hit shift one less time.) More importantly it saves us having to use double quotes at all. This is really useful when you're already using the quotes for something else. For example, running a Perl one-liner remotely with ssh:With 5.10 on the remote machine this becomes just:This has not only the advantage of saving me a bunch of keystrokes, but also doens't make me think as much. And the less I have to think, the less chance I'm going to do something stupid and make a mistake.