开发者

Print freeform text in a Perl function?

I have been getting 开发者_如何转开发a very odd error when trying to print freeform text in a subroutine in Perl. Below is the code I am calling

    print OUTFILE <<"HEADER";
The freeform text would go here
HEADER

The odd thing is that this only works in the main of my function. As soon as I place it in a function call, I get this error:

Can't find string terminator "HEADER" anywhere before EOF

Meaning it can't find the HEADER, even though it is there. Can you not use freeform text within a function (subroutine)?


Make sure that there is no space/tab/indentation before ending string identifier, that is HEADER. Your code should look like this:

        function someFunc(){
          print OUTFILE <<"HEADER";
      The freeform text would go here
HEADER
        }

Notice that there is no space/tab/indentation before HEADER there. It should start from first character of its line.

Check this tutorial out for more information:

  • Perl Here-Doc Tutorial

Quoting:

The important rule to remember is that you finish a here-doc using the same word you started, and it must be by itself on the line

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜