I have noticed an increase in the use of the
__DATA__ token in the posts on PerlMonks. I understand that the data following the
__DATA__ token is not loaded until requested which could be an advantage if you have a large amount of static data. However, I think it is true that same data can only be read once and only in a sequential manner which could be a disadvantage in certain situations. I suppose you could set the file pointer using
seek and get a specific portion of data or re-read the data but that just doesn't sound good to me. With
our declarations, the data is easily reusable in a random access manner but it gets loaded at the beginning whether it's needed later on or not.
I am curious what others think about the use of
__DATA__ versus the use of
our including any specific advantages/disadvantages to either way of doing it. The following examples don't have much data but it's the idea I'm interested in.
#!/usr/bin/perl -w
use strict;
our @data = ("a1","a2","a3","a4","a5","a6","a7","a8","a9","a0");
foreach (@data)
{
print "$_\n";
}
exit;
Versus
#!/usr/bin/perl -w
use strict;
while (<DATA>)
{
print "$_";
}
exit;
__DATA__
a1
a2
a3
a4
a5
a6
a7
a8
a9
a0