syntax error near unexpected token

B

bernard_reims

Hi,
I'm new in perl world.
I suppose the answer to my question is simple .
I did a very basic .pl :

open(FILE, "file.txt");
while(<FILE>){
print "test"
}
close(FILE);

This does not do anything, but when I try to run it, I have this
message
line1: syntax error near unexpected token "FILE,"

Do you know what is the issue ?

Thanks
 
R

Reinhard Pagitsch

Hi,
I'm new in perl world.
I suppose the answer to my question is simple .
I did a very basic .pl :

open(FILE, "file.txt");
while(<FILE>){
print "test"
You forgot the ;.


regards,
Reinhard
 
J

Josef Moellers

Hi,
I'm new in perl world.
I suppose the answer to my question is simple .
I did a very basic .pl :

open(FILE, "file.txt");
while(<FILE>){
print "test"
}
close(FILE);

This does not do anything, but when I try to run it, I have this
message
line1: syntax error near unexpected token "FILE,"

Do you know what is the issue ?

Works for me, if I cut'n'paste your code.
Maybe you have anything in the line above the open(), e.g. some control
character that will change the meaning of the "open("?

Josef
 
P

Paul Lalli

Hi,
I'm new in perl world.
I suppose the answer to my question is simple .
I did a very basic .pl :

open(FILE, "file.txt");
while(<FILE>){
print "test"
}
close(FILE);

This does not do anything, but when I try to run it, I have this
message
line1: syntax error near unexpected token "FILE,"

Do you know what is the issue ?

"Unexpected token" is not a Perl error. It is a shell error. The perl
interpreter was never launched.

My guess is that you put this code into a file, made the file
executable, and tried to just run the file, without ever telling your
environment what program was supposed to run it.

Put these three lines at the top of your file:
#!/usr/bin/perl
use strict;
use warnings;

And try again.

Paul Lalli
 
J

Jürgen Exner

Reinhard said:
(e-mail address removed) wrote:
[syntax error in simple script]
You forgot the ;.

Maybe. I can't tell if the OP meant to write a ; or not.
But at least Perl doesn't require a ; if it's the last command.

Actually I cannot repro the OPs problem:
C:\tmp>perl -c t.pl
t.pl syntax OK

jue
 
P

Paul Lalli

With use strict, it works

WHAT works? Who are you talking to? You are posting to Usenet. Please
follow the conventions that have been in place in Usenet for the last
two decades - quote some context when you post a reply. This is not a
bulletin board, a forum, nor a Google Group.

Your answer, to whatever the question was, is completely not possible.
There is no single script in the world that will "not work" without use
strict, but suddenly "work" with use strict.

You have misinterpreted your results. Unfortunately, you posted
absolutely no code that will allow us to clean up your misconception.

Paul Lalli
 
D

David H. Adler

You forgot the ;.

Although it may be good practice to use a semicolon there, the fact that
it's the last line in a block means it's not required.

dha

--
David H. Adler - <[email protected]> - http://www.panix.com/~dha/
"You're quite free to convert your strings to byte arrays and do the
entire pattern tree by hand in pure logic code if you'd like. By the
time you finish most of the rest of us will be doing contract work on
Mars." - Zenin on comp.lang.perl.misc
 
T

Tad McClellan

But at least Perl doesn't require a ; if it's the last command.


I don't think there is anything in Perl that I could call a "command".

"statement" and "block" are the correct terms, as in perlsyn.pod:

Every simple statement must be terminated with a
semicolon, unless it is the final statement in a block,
in which case the semicolon is optional.
 
E

Eric Bohlman

I don't think there is anything in Perl that I could call a "command".

"statement" and "block" are the correct terms, as in perlsyn.pod:

Every simple statement must be terminated with a
semicolon, unless it is the final statement in a block,
in which case the semicolon is optional.

i.e. in Perl, semicolons are statement *separators* rather then (as in c)
statement *terminators*.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top