We don't bite newbies here... much | |
PerlMonks |
perlfunc:eofby gods (Initiate) |
on Aug 24, 1999 at 22:42 UTC ( [id://241]=perlfunc: print w/replies, xml ) | Need Help?? |
eofSee the current Perl documentation for eof. Here is our local, out-dated (pre-5.6) version: eof - test a filehandle for its end
eof FILEHANDLE eof () eof
Returns 1 if the next read on
FILEHANDLE will return end of file, or if
FILEHANDLE is not open.
FILEHANDLE may be an expression whose value gives the real filehandle. (Note that this function actually reads a character and then
An eof without an argument uses the last file read as argument. Using eof() with empty parentheses is very different. It indicates the pseudo file
formed of the files listed on the command line, i.e., eof() is reasonable to use inside a
# reset line numbering on each input file while (<>) { next if /^\s*#/; # skip comments print "$.\t$_"; } continue { close ARGV if eof; # Not eof()! }
# insert dashes just before last line of last file while (<>) { if (eof()) { # check for end of current file print "--------------\n"; close(ARGV); # close or break; is needed if we # are reading from the terminal } print; } Practical hint: you almost never need to use eof in Perl, because the input operators return false values when they run out of data, or if there was an error. |
|