Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

__DATA___ File Handle

by vivekbks (Initiate)
on Aug 13, 2009 at 08:32 UTC ( [id://788155]=perlquestion: print w/replies, xml ) Need Help??

vivekbks has asked for the wisdom of the Perl Monks concerning the following question:

what is the use of __DATA__ filehandle in Perl.I got information that it is used to read data from that file handle

Replies are listed 'Best First'.
Re: __DATA___ File Handle
by tokpela (Chaplain) on Aug 13, 2009 at 08:47 UTC

    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

      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.
Re: __DATA___ File Handle
by Anonymous Monk on Aug 13, 2009 at 08:51 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://788155]
Approved by vinoth.ree
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-23 09:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found