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

This is a case for applying tye's best practices:
{ my $offset; BEGIN { $offset = tell DATA } sub build_data { seek DATA, $offset, 0; return [ <DATA> ]; } }

That way, even if someone else touches DATA before build_data is called the first time (aka a race condition), it still produces the correct result.

Update: Good point - I stand corrected.

Makeshifts last the longest.

Replies are listed 'Best First'.
Re: Re^2: reading __DATA__ more than once
by japhy (Canon) on Nov 16, 2002 at 15:24 UTC
    You cannot use BEGIN there. See my response earlier, where I do a very similar solution. I use CHECK instead (because Perl has not seen the __DATA__ marker yet, if you use BEGIN).

    _____________________________________________________
    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:??;