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 :-
)

Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery


-- 
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