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\
In reply to Re: "Empty Stream" error as result of repeated reading of __DATA__ block?
by gellyfish
in thread "Empty Stream" error as result of repeated reading of __DATA__ block?
by loris
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |