Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

a tiny syntax error for new commer

Status
Not open for further replies.

szzxy

Technical User
Aug 14, 2010
8
CA
Hello, I am a self-taught new user to perl. Could anyone please take a look at my script and tell me what is going wrong '
[error msg]
syntax error at gene_key.pl line 15, near "){"
syntax error at gene_key.pl line 23, near "}"



#!/usr/local/bin/perl -w
use strict;

open (file1, $ARGV[0]);

my $gene;
my $rs;
my $tf;
my $ds;
my %gene_key;
my @genes



while(<file1>){

if ($_=~/^(.+)\t+(.+)\t+(.+)\t(.+)$/){
$gene=$1;
$rs=$2;
$tf=$3;
$ds=$4;
}



push (@genes, $gene);

foreach $gene (@genes){

$gene_key{$gene}=($3." ".$2." ".$4)

}


foreach $gene(keys %gene_key){

my @gene_table;

push (@gene_table, $gene," ",$gene_key{$gene});

print "$gene.' '.$gene_key{$gene}";

}


}

close (file1);
 
And another missing semi-colon here:

$gene_key{$gene}=($3." ".$2." ".$4)

Should be
$gene_key{$gene}=($3." ".$2." ".$4);
 
Seems like I still have a lot to learn. Thanks a lot for all the replies.
 
Feherke, while it is technically optional, I would always encourage people to use one anyway to avoid later confusion and syntax errors should they add more code to the block.

Annihilannic.
 
Hi

Neither I recommended it, especially not for beginners. I just pointed out that the semicolon's absence mentioned by terryISO does not generate error.

( Personally I omit the semicolon only after the [tt]sub[/tt]s' last statement, the implicitly returned one. That way if I put more statements after that, will throw error instead of returning something undesired. I know I should always use explicit [tt]return[/tt]... )

Feherke.
 
szzxy

Try using one of the many programmer's editors available - jedit is pretty good (and free), but everybody has their own favourites. The coloured syntax highlighting provided by the editor will help you to see the syntax errors as you are coding the program.

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top