| | |
Difference between tr and s
![]() |
tr/// only replaces characters for characters (transliteration). It is very limited but faster than s/// for simple character replacing. s/// is a full blown regexp that can use all of perls various options for pattern matching and substitution.
For example if all you wanted to do was replace all A's with Z's tr is the better choice:
tr/A/Z/;
tr/// can't even use case insensitive matching so to replace all 'A' and 'a' with 'Z' you have to do this:
tr/aA/Z/;
the only useful option with tr/// is the range operator:
tr/a-z/A-Z/
besides that the three basic modifiers are:
c Complement the SEARCHLIST.
d Delete found but unreplaced characters.
s Squash duplicate replaced characters.
see:
http://perldoc.perl.org/perlop.html
for more information
For example if all you wanted to do was replace all A's with Z's tr is the better choice:
tr/A/Z/;
tr/// can't even use case insensitive matching so to replace all 'A' and 'a' with 'Z' you have to do this:
tr/aA/Z/;
the only useful option with tr/// is the range operator:
tr/a-z/A-Z/
besides that the three basic modifiers are:
c Complement the SEARCHLIST.
d Delete found but unreplaced characters.
s Squash duplicate replaced characters.
see:
http://perldoc.perl.org/perlop.html
for more information
![]() |
Similar Threads
- what is the difference between regular and 64 bit edition (Windows NT / 2000 / XP)
- Should replacing a 15" laptop screen with 14.1" make a difference? (Monitors, Displays and Video Cards)
- 56k and 56k/v90 difference? (Windows 95 / 98 / Me)
- date difference in c++ (C++)
- Drawbacks And Difference (C)
- "difference patching" help (C)
- The difference between functions and templates? (C++)
- Difference (Web Browsers)
Other Threads in the Perl Forum
- Previous Thread: Text file formatting by perl
- Next Thread: How to skip a line !
| Thread Tools | Search this Thread |





