in reply to "Empty Stream" error as result of repeated reading of __DATA__ block?
Yes, if you want to read the from the DATA filehandle more than once you need to rewind it to the beginning. Something like:
The reason you have to get the position of the filepointer in DATA with tell is that the DATA filehandle actually refers to the whole program file and is simply left at the beginning of the stuff after the __DATA__ after perl has finished reading in the program - thus if you do seek DATA, 0, SEEK_SET you will be at the start of the program text.use Fcntl; + my $where = tell(DATA); while(<DATA>) { print; } + seek DATA, $where, SEEK_SET; + while(<DATA>) { print; } __DATA__ 1 2 3 4 5 6 7
/J\
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: "Empty Stream" error as result of repeated reading of __DATA__ block?
by NateTut (Deacon) on Aug 17, 2005 at 12:29 UTC | |
|
Re^2: "Empty Stream" error as result of repeated reading of __DATA__ block?
by loris (Hermit) on Aug 17, 2005 at 08:35 UTC | |
by gellyfish (Monsignor) on Aug 17, 2005 at 10:55 UTC |