Re: Using __DATA__ from a packageby Athanasius (Abbot)
|on Jun 18, 2013 at 06:18 UTC||Need Help??|
Consider a driver script “646_SoPW.pl”:
run in conjunction with a module “Test.pm” (in a separate file):
As can be seen, the data section in the module is accessed via __DATA__ from within the module (i.e., within package MyTest), but via MyTest::DATA from within a different package.
But you get the same effect by uncommenting the call to MyTest::run() and using that in place of the second while loop in the driver script. Calling MyTest::run() is better practice as it maintains the encapsulation of the MyTest module.
Note: Trying to combine the two approaches is much more difficult, as it means resetting the DATA handle in the MyTest package. So far, my experiments with open, close, and seek have been less than encouraging. But trying to read the same DATA section twice is probably a bad idea anyway.
Hope that helps,