in reply to Losing __DATA__ when evaling script.
For what it's worth, even though I don't think you should be doing this, the following works for your example:
#!/usr/bin/perl use strict; use warnings; { no warnings "once"; open my $fh, "<", "test.pl"; my $code; while (<$fh>) { last if /^__DATA__/; $code .= $_; } local *DATA = $fh; eval $code; }
However, it will break if test.pl contains a package statement taking it out of the same package as the wrapper script.
|
|---|