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

前端 未结 3 1533
旧巷少年郎
旧巷少年郎 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:10

    From perlop: Quote and Quote-like Operators

    Note that tr does not do regular expression character classes such as \d or [:lower:]. The tr operator is not equivalent to the tr(1) utility. If you want to map strings between lower/upper cases, see lc and uc, and in general consider using the s operator if you need regular expressions.

提交回复
热议问题