CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
Syntax error: word unexpected (expecting ")")


New User

May 19, 2010, 11:11 AM

Post #1 of 3 (1198 views)
Syntax error: word unexpected (expecting ")") Can't Post

So I'm getting this error when I try to run my script and I can't find anything that would be causing this in the script.
This is the code:

open SRCLIST, "qvals_2.dat"
or die "Cannot Open SRCLIST\n";
while(($p1, $p2, $p3, $p4)= split /:/, <SRCLIST>){
system "./popsim2 ${p1} ${p2} ${p3} ${p4} > ${OUTPUT};";
close SRCLIST;

any ideas?

Veteran / Moderator

May 19, 2010, 1:51 PM

Post #2 of 3 (1192 views)
Re: [astro] Syntax error: word unexpected (expecting ")") [In reply to] Can't Post

Don't do the split in the initialization of the loop. That should be done in the body of the loop.

Add this right after the shebang line and fix the problems that they point out.

use strict; 
use warnings;


May 19, 2010, 7:52 PM

Post #3 of 3 (1187 views)
Re: [astro] Syntax error: word unexpected (expecting ")") [In reply to] Can't Post

In addition,

1) Read the following about how to post code:

That is a requirement.

2) Start all your programs with the following lines:

use strict; 
use warnings;
use 5.010; #if using perl 5.10+

3) Declare all variables with my(), e.g.:

my $num; 
my @numbers;
my($num1, $num2) = (3, 4);
my %phone_number_for;

4) Use the 3-arg form of open(), and use a variable instead of a bareword filehandle:

open my $INFILE, '<', 'data.txt' 
or die "Couldn't open data.txt: $!";


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives