Printing string in Perl

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

    You can use the __DATA__ directive which will treat all of the following lines as a file that can be accessed from the DATA handle:

    while () {
       print # or do something else with the lines
    }
    
    __DATA__
    #!/usr/bin/perl -w
    use Some::Module;
    ....
    

    or you can use a heredoc:

    my $string = <<'END';  #single quotes prevent any interpolation
    #!/usr/bin/perl -b
    use Some::Module;
    ....
    END
    

提交回复
热议问题