diff options
-rw-r--r-- | pod/perldata.pod | 2 | ||||
-rw-r--r-- | pod/perlfunc.pod | 15 | ||||
-rw-r--r-- | pod/perlsyn.pod | 8 |
3 files changed, 24 insertions, 1 deletions
diff --git a/pod/perldata.pod b/pod/perldata.pod index 8e2e177e33..572058924f 100644 --- a/pod/perldata.pod +++ b/pod/perldata.pod @@ -644,7 +644,7 @@ values of the array or hash. foreach (@array[ 4 .. 10 ]) { s/peter/paul/ } - foreach (@hash{keys %hash}) { + foreach (@hash{qw[key1 key2]}) { s/^\s+//; # trim leading whitespace s/\s+$//; # trim trailing whitespace s/(\w+)/\u\L$1/g; # "titlecase" words diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index 721b890982..70e604bebf 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -3834,6 +3834,21 @@ operator is discussed in more detail in L<perlop/"I/O Operators">. $line = <STDIN>; $line = readline(*STDIN); # same thing +If readline encounters an operating system error, C<$!> will be set with the +corresponding error message. It can be helpful to check C<$!> when you are +reading from filehandles you don't trust, such as a tty or a socket. The +following example uses the operator form of C<readline>, and takes the necessary +steps to ensure that C<readline> was successful. + + for (;;) { + undef $!; + unless (defined( $line = <> )) { + die $! if $!; + last; # reached EOF + } + # ... + } + =item readlink EXPR =item readlink diff --git a/pod/perlsyn.pod b/pod/perlsyn.pod index 16bca2d6b5..1b5a6a940e 100644 --- a/pod/perlsyn.pod +++ b/pod/perlsyn.pod @@ -315,6 +315,14 @@ hang. # do something } +Using C<readline> (or the operator form, C<< <EXPR> >>) as the +conditional of a C<for> loop is shorthand for the following. This +behaviour is the same as a C<while> loop conditional. + + for ( prompt(); defined( $_ = <STDIN> ); prompt() ) { + # do something + } + =head2 Foreach Loops The C<foreach> loop iterates over a normal list value and sets the |