Hi All,
Hello,
I have to write a code wherein I have to access each character in a string and compare it with '-'
$_ = $seq1[0]; while(/./g) { if($1 eq '-') { $res1[0] .= '-';
^^
}
else {
$res1[0] = "A";
^ Is that supposed to be '.=' instead of '='?
} }
I have initialised $_ with the string in which I have to search.
No need to do that really.
Now I know that the while loop will read each and every character in the string.
I don't know that "read" is the right term, it will iterate over each *non-newline* character.
I just need to get that character read to make the comparison. I know $1 doesnt work because it is not :)
It doesn't work because $1 is set by the first pair of parentheses in the regular expression but you aren't using parentheses to capture the character.
Where is the value returned or how can I assign a variable the value of the condition in the while loop ?
According to your code this will work:
$res1[ 0 ] = join '', 'A', $seq1[ 0 ] =~ /(-+)$/;
But if you really meant to code "$res1[0] .= 'A';" instead of "$res1[0] = 'A';" then this will work:
( $res1[ 0 ] = $seq1[ 0 ] ) =~ s/([^\n-])/A/g;
John -- use Perl; program fulfillment
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
