You need to use string equality. Change == to eqArgument "A" isn't numeric in numeric eq (==)
Another way to do it is with a hash:use warnings; use strict; $_ = 'AAGCTT'; while (/(.)/g) { my $letter = uc $1; print $letter; my $len = length($letter); my $sub = ""; if ( $letter eq "A" ) { $sub = "T"; } elsif ( $letter eq "T" ) { $sub = "A"; } elsif ( $letter eq "G" ) { $sub = "C"; } elsif ( $letter eq "C" ) { $sub = "G"; } print " $len\t$sub\n"; } # close while __END__ A 1 T A 1 T G 1 C C 1 G T 1 A T 1 A
my %conv = ( A => 'T', T => 'A', G => 'C', C => 'G', ); $_ = 'AAGCTT'; while (/(.)/g) { my $letter = uc $1; print $letter; my $len = length($letter); print " $len\t$conv{$letter}\n"; }
In reply to Re: problems with converting a string character by character
by toolic
in thread problems with converting a string character by character
by cburger
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |