7.6. Storing Files Inside Your Program TextProblemYou have data that you want to bundle with your program and treat as though it were in a file, but you don't want it to be in a different file. Solution
Use the
Use while (<DATA>) { # process the line } __DATA__ # your data goes here
Similarly, use while (<main::DATA>) { # process the line } __END__ # your data goes here Discussion
This lets you write self-contained programs that would ordinarily keep data kept in separate files. Often this is used for documentation. Sometimes it's configuration data or old test data that the program was originally developed with, left lying about in case it ever needs to be recreated.
Another trick is to use
use POSIX qw(strftime);
$raw_time = (stat(DATA))[9];
$size = -s DATA;
$kilosize = int($size / 1024) . 'k';
print "<P>Script size is $kilosize\n";
print strftime("<P>Last script update: %c (%Z)\n", localtime($raw_time));
__DATA__
DO NOT REMOVE THE PRECEDING LINE.
See AlsoThe "Scalar Value Constructors" section of perldata (1), and the "Other literal tokens" section of Chapter 2 of Programming Perl Copyright © 2001 O'Reilly & Associates. All rights reserved. |
|