cody
cody

Reputation: 137

This perl code is not working, what mistake am I making?

Can anyone tell me why the below code is showing an error.I am working on perl. I started working on perl right from 5 minutes back.This is my first program in perl.But its saying syntax error unexpected ';' I wrote the code exactly what given in book.but whats the problem ?where does the error lieing?

###!/cygdrive/c/dynasty/gcc/bin

$in =  <<STDIN>> ;

print ($in) ;

and could you suggest me any good pdfs for perl script thank you.

Upvotes: 0

Views: 322

Answers (4)

ysth
ysth

Reputation: 98423

You should have <STDIN> instead of <<STDIN>>. The latter is being parsed as a heredoc (<<STDIN) as the left operand of a right-shift operation (>>), but there's no right operand for the right-shift, hence the unexpected ; error.

Update: except that perl first complains about not finding the STDIN indicating the end of the heredoc. It seems the shell is executing the code instead of perl, and the >> is a redirect, not a right-shift. Otherwise, the above still applies.

Upvotes: 5

Dhaivat Pandya
Dhaivat Pandya

Reputation: 6536

It should be:

$in = <STDIN>;
print ($in);

Also, Modern Perl is an excellent tutorial.

Upvotes: 6

Igor
Igor

Reputation: 27268

The # line

This line tells the machine what to do with the file when it is executed (ie it tells it to run the file through Perl).

STDIN

It should be: my $in = <STDIN>;

Upvotes: 2

odrm
odrm

Reputation: 5259

The correct syntax to read from the STDIN file glob is:

my $in = <STDIN>;

Note - only one set of angle brackets.

Upvotes: 2

Related Questions