Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Overhead of __DATA__?

by stefp (Vicar)
on Sep 05, 2001 at 02:36 UTC ( [id://110187]=note: print w/replies, xml ) Need Help??


in reply to Overhead of __DATA__?

There is less overhead than storing data in a separate file. No seek necessary because the filehandle is already at the right position after the script compilation. Also, if your data section is very long and never explicitely accessed using the DATA handle, it will never be loaded from the disk (except the beginning by normal read-ahead of the OS).

In fact if you "rewind" it by seek( DATA, 0, 0) than do print <DATA> you do print the whole script:

seek( DATA, 0, 0); print <DATA>; __DATA__ this is no quine but downright cheating

note to refute a remark on the CB

To my own surprise: you can pipe this script to Perl and you will get the same result as executing it from a file because of the IO buffering. Indeed, the perl seek() does not translate on a seek() system call. So, if buffering permits, you can perl-seek a non seekable stream!!!

quine page

-- stefp

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://110187]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (6)
As of 2024-03-29 09:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found