If a man speaks in a forest, and his wife's not there, is he still wrong?

perl 6 say function on perl 5

Perl6 has a few "nice" features that just make life that little bit easier. One of them is the "say" function - basically, "print" with a newline.

However, this is also available in perl 5.10 with "use feature 'say'" and in perl 5.8 with "use Perl6::Say".

Here's how to load the right version depending on what version of perl your code is running on:

require 5.008;
BEGIN {
    if ($] <= 5.009) {
        use Perl6::Say;
    } else {
        if ( $] <= 6.000 ) {
            use feature 'say';
        }
    }
}

Note, this won't work on perl 5.8 if the Perl6::Say module is not installed so if you're looking for maximum portability (i.e. only core modules) then rolling your own subroutine is probably the best idea:


BEGIN {
    my $nl = qq(\n);
    *say = sub { print @_, $nl } ;
}

Story Options

perl 6 say function on perl 5 | 0 comments
The following comments are owned by whomever posted them. This site is not responsible for what they say.

Topics

  • Home
  • Misc (6/0)
  • Audio (5/0)
  • Linux (21/0)
  • Family (1/0)
  • Fishing Diary (1/0)
  • OpenSolaris (7/0)
  • Computing (11/0)
  • General News (7/0)
  • Chloe (1/0)
  • Emily (2/0)
  • Twins (5/0)
  • Classifieds (2/0)
  • GeekLog (2/0)
  • Project Management (1/0)
  • User Functions






    Lost your password?