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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



astro
New User

May 19, 2010, 11:11 AM

Post #1 of 3 (1104 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:

#!/usr/bin/perl
open SRCLIST, "qvals_2.dat"
or die "Cannot Open SRCLIST\n";
$OUTPUT='QSpace/qruns/qrun1.dat';
while(($p1, $p2, $p3, $p4)= split /:/, <SRCLIST>){
system "./popsim2 ${p1} ${p2} ${p3} ${p4} > ${OUTPUT};";
}
close SRCLIST;

any ideas?


FishMonger
Veteran / Moderator

May 19, 2010, 1:51 PM

Post #2 of 3 (1098 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.

Code
use strict; 
use warnings;



7stud
Enthusiast

May 19, 2010, 7:52 PM

Post #3 of 3 (1093 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:

http://faq.javaranch.com/java/UseCodeTags

That is a requirement.

2) Start all your programs with the following lines:


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


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


Code
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:


Code
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