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

Re: __DATA___ File Handle

by tokpela (Chaplain)
on Aug 13, 2009 at 08:47 UTC ( #788163=note: print w/replies, xml ) Need Help??

in reply to __DATA___ File Handle

It is a way of using data that is directly placed inside of the script within the __DATA__ section of the file.

It works like a filehandle but does not need to be opened or closed.

For example,

use strict; use warnings; while (<DATA>) { # works just like a file my $line = $_; # removes line feed chomp($line); # ..... add your code here print "LINE: $line\n"; } __DATA__ Line 1 Line 2 Line 3 Line 4

Replies are listed 'Best First'.
Re^2: __DATA___ File Handle
by si_lence (Deacon) on Aug 13, 2009 at 10:35 UTC
    You do not need to open it, but - according to the documentation - you should close it yourself:

    "The filehandle is left open pointing to the contents after __DATA__. It is the program's responsibility to close DATA when it is done reading from it." (Special Literals, as linked by Anonymous Monk).

    cheers, si_lence

      Which is to say that you can close the file handle to release the resources it uses, but Perl will do so automatically when the program exits if it's still open.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://788163]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2018-06-21 23:39 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (120 votes). Check out past polls.