Hi Monks,
Another strange-o that I can't quite find documentation for. Though the pointer to Inline::files may be the ticket, I want Perl to do the following on its own somehow! :-)

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.