The syntax in perl

前端 未结 2 1431
梦如初夏
梦如初夏 2021-01-03 20:09

Where can I find more about the following syntax in perl?

The connection between and __DATA__ is unclear.

whil         


        
相关标签:
2条回答
  • 2021-01-03 20:18

    Everything after __DATA__ is treated as a file you can read from the filehandle DATA. DATA is opened automatically and you don't have to do anything to get it that way.

    What isn't clear? Your program seems to be using it properly.

    0 讨论(0)
  • 2021-01-03 20:30

    Quoting the doc:

    The __DATA__ token tells the perl compiler that the perl code for compilation is finished.

    Everything after the __DATA__ token is available for reading via the filehandle FOOBAR::DATA, where FOOBAR is the name of the current package when the __DATA__ token is reached.

    This works just the same as __END__ does in package 'main', but for other modules data after __END__ is not automatically retrievable, whereas data after __DATA__ is.

    Can add to this only that using __DATA__ section is quite handy to illustrate some file reading-related concepts in Perl. it's basically a file attached to a code, and contents of this file are easily accessible through <DATA>. That's why it's quite popular here on SO. )

    0 讨论(0)
提交回复
热议问题