X-Git-Url: https://perl5.git.perl.org/perl5.git/blobdiff_plain/1b9762da0ef5859330e74d4e715a45cb987232f7..e0ea5e2d50a479e160d39f481e02abd7c0c9cf91:/pod/perlopentut.pod diff --git a/pod/perlopentut.pod b/pod/perlopentut.pod index cd97fdc..9139ebc 100644 --- a/pod/perlopentut.pod +++ b/pod/perlopentut.pod @@ -165,6 +165,33 @@ If you would like to open a bidirectional pipe, the IPC::Open2 library will handle this for you. Check out L +perl-5.6.x introduced a version of piped open that executes a process +based on its command line arguments without relying on the shell. (Similar +to the C notation.) This is safer and faster than executing +a single argument pipe-command, but does not allow special shell +constructs. (It is also not supported on Microsoft Windows, Mac OS Classic +or RISC OS.) + +Here's an example of C, which prints a random Unix +fortune cookie as uppercase: + + my $collection = shift(@ARGV); + open my $fortune, '-|', 'fortune', $collection + or die "Could not find fortune - $!"; + while (<$fortune>) + { + print uc($_); + } + close($fortune); + +And this C pipes into lpr: + + open my $printer, '|-', 'lpr', '-Plp1' + or die "can't run lpr: $!"; + print {$printer} "stuff\n"; + close($printer) + or die "can't close lpr: $!"; + =head2 The Minus File Again following the lead of the standard shell utilities, Perl's @@ -307,7 +334,7 @@ One of the more interesting applications is to change files of a certain name into pipes. For example, to autoprocess gzipped or compressed files by decompressing them with I: - @ARGV = map { /^\.(gz|Z)$/ ? "gzip -dc $_ |" : $_ } @ARGV; + @ARGV = map { /\.(gz|Z)$/ ? "gzip -dc $_ |" : $_ } @ARGV; Or, if you have the I program installed from LWP, you can fetch URLs before processing them: @@ -752,7 +779,7 @@ the doctor ordered. There's no filehandle interface, but it's still easy to get the contents of a document: use LWP::Simple; - $doc = get('http://www.linpro.no/lwp/'); + $doc = get('http://www.cpan.org/'); =head2 Binary Files @@ -917,7 +944,7 @@ second argument contains something else in addition to the usual C<< '<' >>, C<< '>' >>, C<< '>>' >>, C<< '|' >> and their variants, for example: - open(my $fh, "<:utf8", $fn); + open(my $fh, "<:crlf", $fn); =item *