in reply to Re^2: Making a variable from a number in front of a string
in thread Making a variable from a number in front of a string

The <DATA> file handle makes it possible to read the __DATA__ section at the end of the program, i.e. in this case:
__DATA__ (1) Preface What is this all about. (2) Summary of Significant Accounting Policies Revenue Recognition Revenue is recognized at the time goods are sold and shipped. (3) Long-term Debt
It simulates another file and it is a way to quickly test programs without having to create a separate test input file

Replies are listed 'Best First'.
Re^4: Making a variable from a number in front of a string
by Marshall (Canon) on Jul 15, 2016 at 18:22 UTC
    The DATA file handle is actually even a bit cooler than that. To set this up, Perl opens the program for read and then seeks to the first byte after the __DATA__ line. Reading from DATA means that you are actually reading the program file.

    It is possible for the program to "read itself", i.e.:

    #!/usr/bin/perl use warnings; use strict; ## DEMO of reading myself seek (DATA,0,0) or die "unable to seek $!"; print while <DATA>; __DATA__ some data would go here
    To re-read the DATA section, you could use a tell() to figure out where the initial DATA byte is and then later seek back to that initial byte offset.