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 at line 4 : `(' is not expected.

 



mukhtar2t
New User

Feb 14, 2010, 4:31 AM

Post #1 of 8 (2371 views)
Syntax error at line 4 : `(' is not expected. Can't Post

Dear



I have this script h.pl contains:




Code
   

use IO::Socket;

my $sock = new IO::Socket::INET (

LocalHost => 'localhost',

LocalPort => '7070',

Proto => 'tcp',

Listen => 1,

Reuse => 1,

);





But when I execute it, it shows an error:

./h.pl[3]: Syntax error at line 4 : `(' is not expected.


Could any one explain to me what is wrong?



Thanks


mukhtar2t
New User

Feb 14, 2010, 5:29 AM

Post #2 of 8 (2369 views)
Re: [mukhtar2t] Syntax error at line 4 : `(' is not expected. [In reply to] Can't Post

Dear All,

Peace be upon you.

it seems that you are so busy, anyway thank you, I have found out my mistake, I forgot to add #!/usr/bin/perl in the beginning of the script, I hope that someone will get benefit from this later.



Good day for all of you.


(This post was edited by mukhtar2t on Feb 14, 2010, 5:31 AM)


7stud
Enthusiast

Feb 14, 2010, 6:03 AM

Post #3 of 8 (2366 views)
Re: [mukhtar2t] Syntax error at line 4 : `(' is not expected. [In reply to] Can't Post

I don't think so. Your original code runs without error for me.


FishMonger
Veteran / Moderator

Feb 14, 2010, 7:45 AM

Post #4 of 8 (2363 views)
Re: [mukhtar2t] Syntax error at line 4 : `(' is not expected. [In reply to] Can't Post

Please use proper indentation.

It's preferable/better to not use the indirect object syntax.

This is the preferable syntax.

Code
my $sock = IO::Socket::INET->new( 
LocalHost => 'localhost',
LocalPort => 7070,
Proto => 'tcp',
Listen => 1,
Reuse => 1, )
or die "Can't bind : $@\n";



mukhtar2t
New User

Feb 14, 2010, 9:40 AM

Post #5 of 8 (2356 views)
Re: [FishMonger] Syntax error at line 4 : `(' is not expected. [In reply to] Can't Post

Dear FishMonger,

Peace be upon you.

Thank you for your reply, and your recommendation.

I think my code has worked properly for you because you executed it using perl h.pl instead of ./h.pl which I have used.

Best regards,
Mukhtar.


FishMonger
Veteran / Moderator

Feb 14, 2010, 9:51 AM

Post #6 of 8 (2355 views)
Re: [mukhtar2t] Syntax error at line 4 : `(' is not expected. [In reply to] Can't Post


Quote
I think my code has worked properly for you because you executed it using perl h.pl instead of ./h.pl which I have used.

Wrong.


Code
[root@fc4dev ~]# cat h.pl 
#!/usr/bin/perl

use strict;
use warnings;
use IO::Socket::INET;

my $sock = IO::Socket::INET->new(
LocalHost => 'localhost',
LocalPort => 7070,
Proto => 'tcp',
Listen => 1,
Reuse => 1, )
or die "Can't bind : $@\n";

print "we didn't die\n";



Quote
[root@fc4dev ~]# ./h.pl
we didn't die



mukhtar2t
New User

Feb 14, 2010, 9:59 AM

Post #7 of 8 (2353 views)
Re: [FishMonger] Syntax error at line 4 : `(' is not expected. [In reply to] Can't Post

Remove the first line and execute it again please.

#!/usr/bin/perl


FishMonger
Veteran / Moderator

Feb 14, 2010, 10:17 AM

Post #8 of 8 (2350 views)
Re: [mukhtar2t] Syntax error at line 4 : `(' is not expected. [In reply to] Can't Post


In Reply To
Remove the first line and execute it again please.

#!/usr/bin/perl


No, that shebang line needs to be there if you want it execute the script as

./h.pl

instead of

perl h.pl

Without the shebang line your default shell will attempt to run the script instead of the perl interpreter. This is the very reason why you should have a proper shebang line in all scripts no matter the language (perl, python, bash, etc).

 
 


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

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