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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.