What's the difference between tr/// and s/// when using regex in Perl?

前端 未结 3 1541
旧巷少年郎
旧巷少年郎 2020-12-15 04:51

I was wondering when one should use s/// over tr/// when working with regular expressions in Perl?

3条回答
  •  猫巷女王i
    2020-12-15 05:23

    tr/// is not a regular expression operator. It is suitable (and faster than s///) for substitutions of one single character with another single character, or (with the d modifier) substituting a single character with zero characters.

    s/// should be used for anything more complicated than the narrow use cases of tr.

提交回复
热议问题