Thanks, but this won't work. I need to open the data file and read some
data. Later in the script, I need to open the data file again and read
more data. When I use  <DATA>, perl apparently reads one line at a time
until it finds what I want. It then starts at the line I left off when I
need to read more data. It does not start at the beginning again, so I
cannot find the data I need.

The only solution I can think using the __DATA__ method would be to have
my script print out *all* data to a temporary file. I could then open
and close this file when I wanted data. But this seems like kind of a
hack--and it would take a bit more time, though only a second or two.

Paul

On Wed, Feb 05, 2003 at 09:13:13AM -0500, RF wrote:
> 
> >However, I have several files that need aren't modules but are needed
> >for my script. One of these is a data file. How do I set up Makefile.pl
> 
> >to make sure this data file gets put in a place where the script can
> >read it?
> 
> The answer verbatim from The Perl Cookbook
> (http://www.oreilly.com/catalog/cookbook)
> 
> Problem
> 
>                    You 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 __DATA__ or __END__ tokens after your program
> code to mark the start of a data block, which can be
>                    read inside your program or module from the DATA
> filehandle.
> 
>                    Use __DATA__ within a module:
> 
>                    while (<DATA>) {
>                        # process the line
>                    }
>                    __DATA__
>                    # your data goes here
> 
>                    Similarly, use __END__ within the main program file:
> 
>                    while (<main::DATA>) {
>                        # process the line
>                    }
>                    __END__
>                    # your data goes here
> 
>                    Discussion
> 
>                    __DATA__ and __END__ indicate the logical end of a
> module or script before the physical end of file is reached.
>                    Text after __DATA__ or __END__ can be read through
> the per-package DATA filehandle. For example, take the
>                    hypothetical module Primes. Text after __DATA__ in
> Primes.pm can be read from the Primes::DATA filehandle.
> 
>                    __END__ behaves as a synonym for __DATA__ in the main
> package. Text after __END__ tokens in modules is
>                    inaccessible.
> 
>                    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 DATA to find out the current
> program's or module's size or last modification date. On most
>                    systems, the $0 variable will contain the full
> pathname to your running script. On systems where $0 is not correct,
>                    you could try the DATA filehandle instead. This can
> be used to pull in the size, modification date, etc. Put a special
>                    token __DATA__ at the end of the file (and maybe a
> warning not to delete it), and the DATA filehandle will be to
>                    the script itself.
> 
>                    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.
> 
> 
>                    Everything else in this file will be ignored.
> 
>                    See Also
> 
>                    The "Scalar Value Constructors" section of perldata
> (1), and the "Other literal tokens" section of Chapter 2 of
>                    Programming Perl
> 
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]

-- 

************************
*Paul Tremblay         *
*[EMAIL PROTECTED]*
************************

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to