Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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

In reply to Static Data ("__DATA__" vs. "our") by ChrisR

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2024-04-23 21:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found