June 2005
Beginner
480 pages
10h 31m
English
You can read from Perl's filehandles in a couple of different ways. The most common method is to use the file input operator, also called the angle operator (<>). To read a filehandle, simply put the filehandle name inside the angle operator and assign the value to a variable:
open(MYFILE, "myfile") || die "Can't open myfile: $!"; $line=<MYFILE>; # Reading the filehandle
The angle operator in a scalar context reads one line of input from the file. When called after the entire file has been read, the angle operator returns the value undef.
By the Way
A “line of input” is usually considered to be a text stream until the first end-of-line sequence is found. In Unix, that end-of-line sequence is a newline character (ASCII 10); in DOS and ...
Read now
Unlock full access