[ABE.pm] perl 5.10 rules! - say what?

Walt Mankowski waltman at pobox.com
Thu May 31 19:49:03 PDT 2007


On Thu, May 31, 2007 at 11:23:27AM -0400, Ricardo SIGNES wrote:
> 
> Here's another little one:  say
> 
> say is stolen from Perl 6.  It's just like print, but it prints a newline when
> you're done.  Seriously, that's it!
> 
>   print "Nice to meet you, ", $ENV{USER}, ".\n";
>   say "Nice to meet you, ", $ENV{USER}, ".";
> 
> Those lines do the same thing.
> 
> What's the big deal?  Well, you save four keystrokes, for one, multiplied by
> every time you would've used print.

You could, of course, have saved *six* keystrokes by changing that
first line to

  print "Nice to meet you, $ENV{USER}.\n";

and it's a lot clearer that you've got the space and period where you
want them.

I agree with Mike in wishing they'd called it "puts" like ruby and
stdio.h do.  "say" just seems a bit too cutesy.

> Then there's this:
> 
>   print @lines, "\n";
>   say @lines;
> 
> There you saved eight keystrokes!
> 
> Is this a really small win?  I don't know, I think it's a tiny improvement that
> you'll really grow to love.
> 
> There's one thing to keep in mind:  because "say" wasn't a keyword before 5.10,
> you'll want to let perl know that you want it to be one now.  There are a few
> ways to do that:
> 
>   use feature 'say';   # turn on the "say" feature in this block or file
>   use feature ':5.10'; # turn on all 5.10 features in this block or file
> 
>   perl -E 'say "Hello, world!"' # like perl -e, but with all features

There go all the keystrokes you just saved!  :)

Walt


More information about the ABE-pm mailing list