diff options
author | Shlomi Fish <shlomif@vipe.technion.ac.il> | 2008-09-23 22:00:41 +0300 |
---|---|---|
committer | Rafael Garcia-Suarez <rgarciasuarez@gmail.com> | 2008-09-27 15:22:20 +0000 |
commit | 494bd33348b985a58018f4b68f5d051cf954d541 (patch) | |
tree | b489048ac86dbf6f33e589acac45f5d5f904b594 /pod/perlopentut.pod | |
parent | bb07982c124f18c3f2fabd8491bf0aecf9cbf009 (diff) | |
download | perl-494bd33348b985a58018f4b68f5d051cf954d541.tar.gz |
Re: [PATCH] Add open "|-" and open "-|" to perlopentut
Message-id: <200809231900.41474.shlomif@iglu.org.il>
p4raw-id: //depot/perl@34435
Diffstat (limited to 'pod/perlopentut.pod')
-rw-r--r-- | pod/perlopentut.pod | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/pod/perlopentut.pod b/pod/perlopentut.pod index 566ba0f721..31fe6f22e9 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<perlipc/"Bidirectional Communication with Another Process"> +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<system(@LIST)> 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 RiscOS.) + +Here's an example of C<open '-|'>, 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<open '|-'> 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 |