Printing string in Perl

后端 未结 6 1606
爱一瞬间的悲伤
爱一瞬间的悲伤 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:19

    The printing is not doing special things to the escapes, double quoted strings are doing it. You may want to try single quoted strings:

    print 'this is \n', "\n";
    

    In a single quoted string the only characters that must be escaped are single quotes and a backslash that occurs immediately before the end of the string (i.e. 'foo\\').

    It is important to note that interpolation does not work with single quoted strings, so

    print 'foo is $foo', "\n";
    

    Will not print the contents of $foo.

提交回复
热议问题