开发者

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 scrip开发者_运维知识库t thank you.


It should be:

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

Also, Modern Perl is an excellent tutorial.


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.


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

my $in = <STDIN>;

Note - only one set of angle brackets.


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>;

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜