Nathan Jones
Nathan Jones

Reputation: 5174

Syntax error reading and reversing STDIN

I'm just starting to learn Perl today by going through Modern Perl, but one of the examples is tripping me up. The book has this code:

while (<>)
{
  chomp;
  say scalar reverse;
}

Running this code with the command perl stdin.pm hi.txt or cat hi.txt | perl stdin.pm gives me this error:

syntax error at stdin.pm line 4, near "say scalar"
Execution of stdin.pm aborted due to compilation errors.

The contents of hi.txt are:

hi
how
are
you

What am I doing wrong?

Upvotes: 0

Views: 135

Answers (1)

mpapec
mpapec

Reputation: 50667

You can enable say feature

use feature `say`;

or use what author of the book suggest,

use Modern::Perl;

Upvotes: 2

Related Questions