next up previous contents
Next: Example: Using the %ENV Up: Special Variables Previous: What Are the Special

Example: Using the DATA File Handle

As you no doubt realize by now, Perl has some really odd features, and the DATA file handle is one of them. This file handle lets you store read-only data in the same file as your Perl script, which might come in handy if you need to send both code and data to someone via e-mail.

When using the DATA file handle, you don't need to open or close the file handle-just start reading from the file handle using the diamond operator. The following simple example shows you how to use the DATA file handle. The mothod is simple enough:

The Perl to do this is (data.pl):

@lines = <DATA>;



foreach (@lines) {

    print("$_");



}



__END__

Line one

Line two

Line three

This program displays the following:

Line one

Line two

Line three



dave@cs.cf.ac.uk