Printing string in Perl

后端 未结 6 1640
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-15 04:39

Is there an easy way, using a subroutine maybe, to print a string in Perl without escaping every special character?

This is what I want to do:

print          


        
6条回答
  •  旧巷少年郎
    2021-01-15 05:30

    perldoc perlop, under "Quote and Quote-like Operators", contains everything you need.

    While we usually think of quotes as literal values, in Perl they function as operators, providing various kinds of interpolating and pattern matching capabilities. Perl provides customary quote characters for these behaviors, but also provides a way for you to choose your quote character for any of them. In the following table, a "{}" represents any pair of delimiters you choose.

    Customary  Generic        Meaning        Interpolates
        ''       q{}          Literal             no
        ""      qq{}          Literal             yes
        ``      qx{}          Command             yes*
                qw{}         Word list            no
        //       m{}       Pattern match          yes*
                qr{}          Pattern             yes*
                 s{}{}      Substitution          yes*
                tr{}{}    Transliteration         no (but see below)
        <

提交回复
热议问题