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 | [reply] [d/l] [select] |
#!/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. | [reply] [d/l] |
Maybe we didn't give you a crystal clear reply. First, the program should run using the data segment. Then take the data after __DATA__ and put that into "somefile". In the program, you need to add at the beginning,
open FILE, '<', "somefile" or die "unable to open file $!";
Now put FILE everywhere that DATA appears in the program. You will now be reading "somefile" on the disk instead of the __DATA__ section. | [reply] [d/l] |