Printing string in Perl

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

    You can pretty much use any character you want with q or qq. For example:

    #!/usr/bin/perl
    
    use utf8;
    use strict; use warnings;
    
    print q∞This is a test∞;
    print qq☼\nThis is another test\n☼;
    print q»But, what is the point?»;
    print qq\nYou are just making life hard on yourself!\n;
    print qq¿That last one is tricky\n¿;
    

    You cannot use qq DELIMITER foo DELIMITER. However, you could use heredocs for a similar effect:

    print <

    or

    print <<'DELIMETER'
    ...
    DELIMETER
    ;
    

    but your source code would be really ugly.

提交回复
热议问题