diff options
author | Dominic Dunlop <domo@slipper.ip.lu> | 1997-06-16 11:36:14 +1200 |
---|---|---|
committer | Tim Bunce <Tim.Bunce@ig.co.uk> | 1997-08-07 00:00:00 +1200 |
commit | 08e9d68e93f9880dc9a1edcde3abb85026f49784 (patch) | |
tree | 91b1649fae5e4a3033997482c0e2c988f8e0af20 /pod/perlrun.pod | |
parent | 7bc39d6220d2b77d9c5827625d97cd2af6ef9c56 (diff) | |
download | perl-08e9d68e93f9880dc9a1edcde3abb85026f49784.tar.gz |
-p does not check for failure of implicit print
Unlike modern incarnations of, say, awk and sed, perl -p does not check the
return status of the implicit print statement executed for each input
record.
Here's a patch against 5.004_01. ('ware wrapping: there's a long line
in it.) There's no test case: I couldn't think up a reliable,
portable and polite way of inducing a write error.
I think, in the specific case of the implicit print in -p, this is
non-controversial, and can go in the maintenance branch. That's not to say
that there are not programs using -p out there (probably CGI scripts) which
will surprise people by exiting noisily on encountering an error, rather
than continuing to do thewrong thing quietly. Does anybody know of any
widespread examples? Do we care?
More controversial error checking patch for implicit close of <ARGV>
to follow in separate bug report.
p5p-msgid: v0311070aafea3fa83061@[194.51.248.75]
Diffstat (limited to 'pod/perlrun.pod')
-rw-r--r-- | pod/perlrun.pod | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/pod/perlrun.pod b/pod/perlrun.pod index de7116d939..61e40f88a0 100644 --- a/pod/perlrun.pod +++ b/pod/perlrun.pod @@ -376,8 +376,10 @@ B<awk>: } Note that the lines are not printed by default. See B<-p> to have -lines printed. Here is an efficient way to delete all files older than -a week: +lines printed. If a file named by an argument cannot be opened for +some reason, Perl warns you about it, and moves on to the next file. + +Here is an efficient way to delete all files older than a week: find . -mtime +7 -print | perl -nle 'unlink;' @@ -396,11 +398,14 @@ makes it iterate over filename arguments somewhat like B<sed>: while (<>) { ... # your script goes here } continue { - print; + print or die "-p destination: $!\n"; } -Note that the lines are printed automatically. To suppress printing -use the B<-n> switch. A B<-p> overrides a B<-n> switch. +If a file named by an argument cannot be opened for some reason, Perl +warns you about it, and moves on to the next file. Note that the +lines are printed automatically. An error occuring during printing is +treated as fatal. To suppress printing use the B<-n> switch. A B<-p> +overrides a B<-n> switch. C<BEGIN> and C<END> blocks may be used to capture control before or after the implicit loop, just as in awk. |