Ci-dessous est un script où j'essaie d'inverser puis de substituer (A => T, T => A, G => C, C => G).Subsitution simultanée en Perl
VERSION 1
#!/usr/bin/perl
my $str="AAAAAGCTTGC";
$str_rev=scalar reverse ("$str"),"\n";
print"My original string: $str\n";
print "My reversed string: $str_rev\n";
$str_rev =~ s/A/T/g;
$str_rev =~ s/T/A/;
$str_rev =~ s/G/C/g;
$str_rev =~ s/C/G/;
print"My substituted reversed string: $str_rev\n";
SORTIE:
My original string: AAAAAGCTTGC
My reversed string: CGTTCGAAAAA
My substituted reversed string: GCATCCTTTTT
global pour toutes les substitutions (version 2)
$str_rev =~ s/A/T/g;
$str_rev =~ s/T/A/g;
$str_rev =~ s/G/C/g;
$str_rev =~ s/C/G/g;
print"My substituted reversed string: $str_rev\n";
SORTIE:
My original string: AAAAAGCTTGC
My reversed string: CGTTCGAAAAA
My substituted reversed string: GGAAGGAAAAA
Dans la première version, j'observe que les substitutions qui ne sont pas globales, sont substituées une fois (évidemment, puisque ce n'est pas global). Et dans la version 2, puisqu'il traite le code de haut en bas, la dernière substitution ignore le "G" restant. Je voulais toutes les substitutions en parallèle. Comment puis-je réaliser cela dans une chaîne?
Merci! Cela a fonctionné sans le "g";) – user1504209