in reply to Re^2: How to use __DATA__ efficiently, help!
in thread How to use __DATA__ efficiently, help!
But how to use multiple sets of "__DATA__" still stands.
The answer is simple: you can't. There's only one __DATA__ section. At least in the main package.
In other words, you'd have to use some separator, e.g. an empty line (if that doesn't occur otherwise in the data), and then split it up into sets yourself.
You could in theory put different __DATA__ sections in different modules (i.e. different packages in different files), and then access them as Foo::DATA, etc., but you might as well just put the data sets in normal files and read them from there...
# File Set1.pm package Set1; 1; __DATA__ foo1 foo2 foo3 # File Set2.pm package Set2; 1; __DATA__ bar1 bar2 bar3 # main script #!/usr/bin/perl -w use strict; use Set1; use Set2; print "Set 1:\n"; while (<Set1::DATA>) { print } print "Set 2:\n"; while (<Set2::DATA>) { print }
Output:
Set 1: foo1 foo2 foo3 Set 2: bar1 bar2 bar3
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: How to use __DATA__ efficiently, help!
by belden (Friar) on Feb 10, 2011 at 16:30 UTC | |
by Anonyrnous Monk (Hermit) on Feb 10, 2011 at 17:32 UTC |