in reply to Re: reading __DATA__ more than once
in thread reading __DATA__ more than once

Thank you! It hadn't occurred to me that the value landing in my $offset could persist through every time I entered the package to use its sub. Much less am I aware of the true workings of __DATA__ and using seek & tell to play with it. :-)

As for "fast food", I'd say about 1% of the main program's data is accessed this way, 99% comes in traditional fat free ways. But "needs of the business" seem to require accessing this particular chunk of data in a more devious way... Are there side effects I should be aware of if I operate in this way? Besides its just being creepy?

Replies are listed 'Best First'.
Re: Re: reading __DATA__ more than once
by japhy (Canon) on Nov 14, 2002 at 15:52 UTC
    The value sticks around because I don't create in the function, but in the scope surrounding the function. If you've got Perl 5.6, here's a cooler way to do it:
    { my $offset; CHECK { $offset = tell DATA } sub data { seek DATA, $offset, 0; [<DATA>] } }
    The CHECK block happens just after compile-time ends.

    _____________________________________________________
    Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;