The tr operator in Perl translates all characters of SearchList into the corresponding characters of ReplacementList. Here the SearchList is the given input characters which are to be converted into the corresponding characters given in the ReplacementList.
It is the smartmatch operator. In general, when you want information about operators in Perl, see perldoc perlop.
m operator in Perl is used to match a pattern within the given text. The string passed to m operator can be enclosed within any character which will be used as a delimiter to regular expressions.
$@ The Perl syntax error or routine error message from the last eval, do-FILE, or require command. If set, either the compilation failed, or the die function was executed within the code of the eval.
I want to remove diacritic signs in some strings. tr///
should do the job but fails (see below). I thought I had an encoding/decoding problem, but I noticed s///
works as I expect. Could somebody explain why?
Here is an example of results I get:
my $str1 = 'èîü';
my $str2 = $str1;
$str1 =~ tr/î/i/;
print "$str1\n"; # => i�iii�
$str2 =~ s/î/i/;
print "$str2\n"; # => èiü
Note that tr///
also modified the first and third characters of the string, not just the middle one.
Edit: I use Ubuntu 16.04 with Mate desktop environment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With