-4

I am using Perl for string manipulation and that involves use of the reverse function and of tr to translate my string. The script reads some strings and then performs following:

$revread = reverse($newword);
$revread =~ tr/TACGN/ATGCN/;

So the word is reversed and then gets translated--reverse complement. I have following question:

What if

$revread=~ tr/TACG/ATGC/;

is used. In this case if "N" is found will it be skipped? as in tr I have nothing there to translate it to OR it will be printed as just as "N".

Sinan Ünür
  • 116,958
  • 15
  • 196
  • 339
Sudeep
  • 3,015
  • 3
  • 17
  • 8

2 Answers2

5

Yes, anything that is not specified inside to tr will be left alone.

The documentation for tr/// is a little hard to get to as it's detailed examples are listed in perldoc perlop rather than the usual perldoc perlfunc

Zaid
  • 36,680
  • 16
  • 86
  • 155
2

Aleks G has the correct answer: Just try it.

I tried it. I found that:

> perl -wE '$x = qq(abcdefg); $x=~ tr/abc/123/; say $x;'
123defg

Any characters not found in the transliteration are left as they are. Documentation here.

TLP
  • 66,756
  • 10
  • 92
  • 149