Home > Archive > PERL Beginners > October 2006 > regular expression syntax
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
regular expression syntax
|
|
| Kathryn Bushley 2006-10-20, 6:56 pm |
| Hi,=0A=0AI'm trying to get this program to work and it works up until the l=
ast two lines (substitution) which gives a syntax error...any idea what mig=
ht be the problem?=0A=0Athanks,=0A=0Akathryn=0A=0A=0A#!/usr/bin/perl -w=0Au=
se warnings;=0A=0Ause Bio::Seq;=0Ause Bio::SeqIO;=0A=0A#initialize id and f=
asta files=0Amy $codefile =3D $ARGV[0];=0Amy $treefile =3D $ARGV[1];=0A=0A#=
open alignment list and create a global hash of tree codes with species nam=
e as =0A#open gi id file and assign file handle=0Aopen(ID,$codefile)|| die =
"can't open id file: $!\n";=0A#initialize hash=0Amy(@ID);=0Amy %id_global;=
=0Amy $id;=0Awhile (<ID> ){=0A #split on spaces=0A my @ID =3D split(/\s+/)=
;=0A #print "ID->".$ID[0]."<-\n"."Code->".$ID[1]."<-\n";=0A #get rid of c=
arriage returns=0A chomp;=0A #define id as the code number=0A my $id =3D=
$ID[1];=0A #print "ID->".$id."<-\n";=0A #create a global hash with code =
number as key and species name as value=0A $id_global{$id}=3D $ID[0]; =0A =
#print $id."VALUE->".$id_global{$id}."<-\n";=0A}=0A=0A=0A#test that keys l=
oaded to global hash with correct value=0A#foreach my $key (keys %id_global=
){=0A#print "KEY->".$key."<-->VALUE->".$id_global{$key}."<-\n";=0A#}=0A=0A=
=0A#open treefile and while through it, substituting species name value whe=
n key found in file.=0Aopen (TREE,$treefile)|| die "can't open tree file: $=
\n";=0Awhile (<TREE> ){=0A foreach my $code (keys %id_global){=0A #print=
"CODE->".$code."<-VALUE->".$id_global{$code}."\n";=0A $line =3D $_;=0A =
#if ($line =3D~ m/(.*)$code([\D])/) {print "MATCH"." ".$code."VALUE->".$id=
_global{$code}."<-\n";} =0A #else {print "NO MATCH"." ".$code=
.."<-\n";} #works,matches all values w/right val=0A $line=3D~ s/(.*)$code(=
[/D])/$1$id_global{$code}$2/;=0A print $line;=0A }=0A}=0A=0A=0A
| |
| Tom Phoenix 2006-10-20, 6:56 pm |
| On 10/20/06, Kathryn Bushley <kbushley@yahoo.com> wrote:
> I'm trying to get this program to work and it works up until the last two lines
> (substitution) which gives a syntax error...any idea what might be the problem?
What *is* the error message?
> $line=~ s/(.*)$code([/D])/$1$id_global{$code}$2/;
An s/// operator should have three delimiter characters, but you seem
to have four. Was that what the error message was trying to tell you?
Hope this helps!
--Tom Phoenix
Stonehenge Perl Training
| |
| Dr.Ruud 2006-10-21, 7:56 am |
| Kathryn Bushley schreef:
> #!/usr/bin/perl -w
> use warnings;
You have both -w and lexical warnings.
Read `perldoc perllexwarn` or
http://perldoc.perl.org/perllexwarn.html
Now first change your two lines to these three:
#!/usr/bin/perl
use warnings ;
use strict ;
and see what extra help Perl gives you.
> my @ID = split(/\s+/);
Almost always this is equivalent or better:
my @ID = split ;
Read "-f split" about the difference.
> chomp;
Normally the chomp is at the top of the loop-body. I think you forgot to
take it out.
There are a lot of dead lines in your code. Maybe you should start using
something like this:
use constant DEBUG => 1 ;
[...]
if (DEBUG) { print "ID->${ID[0]}<-\n" . "Code->${ID[1]}<-\n" }
--
Affijn, Ruud
"Gewoon is een tijger."
|
|
|
|
|