If you are stuck with pre-5.10, then the solutions above will not fully replicate the say function. for example
sub say { print @_, "\n"; }
Will not work with calls such as
say for @arr;
or
for (@arr) { say; }
... because the above function does not affect the implicit global $_ as print and the real say function.
To more accurately reproduce perl 5.10+ say , you need this function
sub say { if (@_) { print @_, "\n"; } else { print $_, "\n"; } }
Now it acts like
my @arr = qw( alpha beta gamma ); say @arr;
say built-in perl6 behaves a little differently. A call with say @arr or @arr.say will not just be a concatenation of the elements of the array, but will instead print them, separated by a list separator. To reproduce this in perl5 you will do it
sub say { if (@_) { print join($", @_) . "\n"; } else { print $_ . "\n"; } }
$" is a global list separator variable, or if you are using English.pm , i.e. $LIST_SEPARATOR
Now it will be more like perl6, so
say @arr;
Joshua Aug 03 '15 at 0:02 2015-08-03 00:02
source share