Oh come on.
Please read between the lines. The poster obviously doesn't know how DATA really works, and it's not how to do file IO he's asking about. He wants to learn about DATA and probably use it in his script and try it out. I think it's good to strive for greater understanding. If the problem is that you don't think he should be doing that by himself then just explain why, and then give him the alternative safe solution.
Inline::Files is good and all, but it can also be total overkill. I like Inline::Files when I want to have several DATA filehandles, but when you just want one the only thing that differes DATA from any other filehandle is that it's preopened and that it's sought to some non-BOF location.
Inline::Files plus Inline::Files::Virtual is about 500 lines of Perl, using tieing and AUTOLOADing, fiddles with the CORE::GLOBAL namespace, and utilizes the Filter module--which is XS.
I just wrote a program that checks the difference between a perl -e0 and perl -MModule -e0 on ActivePerl 5.8.0 build 806. The numbers in parenthesis in the approximate line count; POD, __END__/__DATA__, comments, and blank lines stripped (all pretty imperfectly done). The last number is the sum of the above. Empty (with my definition of empty) packages are filtered out.
Here's the output for Inline::Files:
New packages:
AutoLoader
Carp
Config
Cwd
DB
Data::Dumper
Dos
EPOC
Exporter
Filter::Util::Call
Inline::Files
Inline::Files::Data
Inline::Files::Virtual
Mac::FileSpec::Unixish
VMS::Filespec
XSLoader
base
fields
strict
vars
warnings
warnings::register
New files:
( 117) AutoLoader.pm
( 41) Carp.pm
(1122) Config.pm
( 325) Cwd.pm
( 125) DynaLoader.pm
( 59) Exporter.pm
( 33) Filter/Util/Call.pm
( 139) Inline/Files.pm
( 351) Inline/Files/Virtual.pm
( 55) XSLoader.pm
( 40) base.pm
( 21) strict.pm
( 39) vars.pm
( 316) warnings.pm
( 26) warnings/register.pm
(2809)
Now compare this to
my $BOF = tell DATA;
open my $data, '+<', $0 or die ...;
seek $data, $BOF, 0 or die ...;
and pretty much all you need to remember is that BOF isn't 0 but $BOF.
I'm surprised to see you give this advice, since I've seen you elsewhere advocate to not invoke modules when they mean "unnecessary" overhead: "the code I posted elsewhere in this thread copies the method of the module, without even having to invoke the overhead of the module". In fact, I even disagree with you there, and think that constant.pm should be utilized there. :-) Funny, heh.
ihb |