Jenda Krynicky wrote:
From: "John W. Krahn" <[EMAIL PROTECTED]>

[EMAIL PROTECTED] wrote:

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 '='?

}
}

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;

tr/// would be quicker.

        ( $res1[ 0 ] = $seq1[ 0 ] ) =~ tr/-/A/c;

Of course this assumes that mk76 really meant "each character" and not "each character except newline". So this is not consistent with what his original code (almost) did, but with what he said he wants :-)

"each character except newline" will still work with tr///. ;-)

      ( $res1[ 0 ] = $seq1[ 0 ] ) =~ tr/-\n/A/c;



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>




Reply via email to