Saturday, March 16, 2013

Effective Perl Programming Book

I opened the book Effective Perl Programming and found a new function in Perl, "Perl 5.10 adds a say built-in that is just like print except that it adds the trailing newline for you".
$s = <stdin>;
foreach ($s) {
 print;
}
Running the code simply outputs the input:
[perl] perl helloworld.pl
hello world
hello world
[perl]

Simply replacing print with say doesn't work. The use feature statement is required for the code to run.
use feature ':5.12.4';
$s = <STDIN>;
foreach ($s) {
 say;
}