in reply to Re: Reliably simulating 5.10 say()
in thread Reliably simulating 5.10 say()

Thanks, but that gives me the error:
Not enough arguments for main::say at a.pl line 10, near "say foreach +" Malformed prototype for main::say: _ at a.pl line 13.

Replies are listed 'Best First'.
Re^3: Reliably simulating 5.10 say()
by Laurent_R (Canon) on Feb 08, 2015 at 17:51 UTC
    Perhaps it is a relatively new feature. Which version of Perl are you running?

    The same code works for me in Perl 5.14.

    Update: I did not see it before I posted the above, but several people have responded below that it is a feature that was introduced in version 5.10.

    Je suis Charlie.
Re^3: Reliably simulating 5.10 say()
by Laurent_R (Canon) on Feb 08, 2015 at 15:00 UTC
    It works perfectly for me. Please show the exact code that you tested and gave this error.

    Je suis Charlie.
      #!/usr/bin/env perl + + use strict; + use warnings; + + sub say (_) { + print @_, "\n"; } + + my @a = qw(1 2 3); + + # using implicit $_ does not work: + say foreach (@a); + + # ...and of course explicit $_ works. + say $_ foreach (@a); + + # works: + say "uncle bob";
      The error for above:
      Illegal character in prototype for main::say : _ at a.pl line 6. Not enough arguments for main::say at a.pl line 13, near "say foreach +" Malformed prototype for main::say: _ at a.pl line 16.