on C<OLD>. Formerly, it would have returned the data from the start
of the following disk block instead.
+=head2 eof() has the same old magic as <>
+
+C<eof()> would return true if no attempt to read from C<E<lt>E<gt>> had
+yet been made. C<eof()> has been changed to have a little magic of its
+own, it now opens the C<E<lt>E<gt>> files.
+
=head2 system(), backticks and pipe open now reflect exec() failure
On Unix and similar platforms, system(), qx() and open(FOO, "cmd |")
C<eof(FILEHANDLE)> on it) after end-of-file is reached. File types such
as terminals may lose the end-of-file condition if you do.
-An C<eof> without an argument uses the last file read as argument.
-Using C<eof()> with empty parentheses is very different. It indicates
-the pseudo file formed of the files listed on the command line,
-i.e., C<eof()> is reasonable to use inside a C<while (E<lt>E<gt>)>
-loop to detect the end of only the last file. Use C<eof(ARGV)> or
-C<eof> without the parentheses to test I<each> file in a while
-(E<lt>E<gt>) loop. Examples:
+An C<eof> without an argument uses the last file read. Using C<eof()>
+with empty parentheses is very different. It refers to the pseudo file
+formed from the files listed on the command line and accessed via the
+C<E<lt>E<gt>> operator. Since C<E<lt>E<gt>> isn't explicitly opened,
+as a normal filehandle is, an C<eof()> before C<E<lt>E<gt>> has been
+used will cause C<@ARGV> to be examined to determine if input is
+available.
+
+In a C<while (E<lt>E<gt>)> loop, C<eof> or C<eof(ARGV)> can be used to
+detect the end of each file, C<eof()> will only detect the end of the
+last file. Examples:
# reset line numbering on each input file
while (<>) {
This is usually 32766 on the most common platforms. The actual limit can
be seen in the error message generated by code such as this:
- $_ **= $_ , / {$_} / for 2 .. 42;
+ $_ **= $_ , / {$_} / for 2 .. 42;
By default, a quantified subpattern is "greedy", that is, it will match as
many times as possible (given a particular starting location) while still
The POSIX character class syntax
- [:class:]
+ [:class:]
is also available. The available classes and their backslash
equivalents (if available) are as follows:
Note that the C<[]> are part of the C<[::]> construct, not part of the whole
character class. For example:
- [01[:alpha:]%]
+ [01[:alpha:]%]
matches one, zero, any alphabetic character, and the percentage sign.
=item cntrl
- Any control character. Usually characters that don't produce
- output as such but instead control the terminal somehow:
- for example newline and backspace are control characters.
- All characters with ord() less than 32 are most often control
- classified as characters.
+Any control character. Usually characters that don't produce output as
+such but instead control the terminal somehow: for example newline and
+backspace are control characters. All characters with ord() less than
+32 are most often control classified as characters.
=item graph
- Any alphanumeric or punctuation character.
+Any alphanumeric or punctuation character.
=item print
- Any alphanumeric or punctuation character or space.
+Any alphanumeric or punctuation character or space.
=item punct
- Any punctuation character.
+Any punctuation character.
=item xdigit
- Any hexadecimal digit. Though this may feel silly
- (/0-9a-f/i would work just fine) it is included
- for completeness.
+Any hexadecimal digit. Though this may feel silly (/0-9a-f/i would
+work just fine) it is included for completeness.
=item
#!./perl
-print "1..6\n";
+BEGIN {
+ chdir 't' if -d 't';
+ unshift @INC, '../lib';
+}
+
+print "1..14\n";
+
+use File::Spec;
+
+my $devnull = File::Spec->devnull;
open(try, '>Io.argv.tmp') || (die "Can't open temp file: $!");
print try "a line\n";
}
if ($x eq "foo\n") {print "ok 3\n";} else {print "not ok 3 :$x:\n";}
-@ARGV = ('Io.argv.tmp', 'Io.argv.tmp', '/dev/null', 'Io.argv.tmp');
+@ARGV = ('Io.argv.tmp', 'Io.argv.tmp', $devnull, 'Io.argv.tmp');
while (<>) {
$y .= $. . $_;
if (eof()) {
open(try, '<Io.argv.tmp') or die "Can't open temp file: $!";
print while <try>;
close try;
+undef $^I;
+
+eof try or print 'not ';
+print "ok 7\n";
+
+eof NEVEROPENED or print 'not ';
+print "ok 8\n";
+
+open STDIN, 'Io.argv.tmp' or die $!;
+@ARGV = ();
+!eof() or print 'not ';
+print "ok 9\n";
+
+<> eq "ok 6\n" or print 'not ';
+print "ok 10\n";
+
+open STDIN, $devnull or die $!;
+@ARGV = ();
+eof() or print 'not ';
+print "ok 11\n";
+
+@ARGV = ('Io.argv.tmp');
+!eof() or print 'not ';
+print "ok 12\n";
+
+@ARGV = ($devnull, $devnull);
+!eof() or print 'not ';
+print "ok 13\n";
+
+close ARGV or die $!;
+eof() or print 'not ';
+print "ok 14\n";
END { unlink 'Io.argv.tmp', 'Io.argv.tmp.bak' }