I have a program that requires package files containing subroutines. My main program invokes a subroutine from this package several times whose job it is to collect the stuff after <DATA> and return it to me via an array ref, something like:
package foo; use strict; sub build_data { my @ra = (); @ra = <DATA>; return (\@ra); } 1; __DATA__ DAY1 asas aerer DAY1 qwrep poiu wer DAY2 faas dfa sdf as
My problem is that only the first invocation of the subroutine reads the contents of <DATA>. Successive invocations return an empty array. My reading finds that closeing a filehandle prepares it to be read again from the top. But how do you close <DATA>? And setting $. = 1; (or maybe '0'?) doesn't do much either. Hmm.
My data is structured like this because it's easy to append more "data" to this package file and thus be available to the overall program without being in a separate text file. I have since rewritten this portion such that instead of appending new data that I generate from day to day to a __DATA__ section, it gets strategically inserted four lines before the end of the .pl package file where it effectively becomes CONSTANT data to be absorbed by an array of another subroutine of package foo, and thus as an array is returnable to my overall calling program. But lazy me, it irritated me to undo my __DATA__ approach. What did I miss?
In reply to reading __DATA__ more than once by ff
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |