[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]
[PATCH] Add open "|-" and open "-|" to perlopentut
This patch documents open "|-" and open "-|" in perlopentut. It is against
bleadperl.
Regards,
Shlomi Fish
-----------------------------------------------------------------
Shlomi Fish http://www.shlomifish.org/
Understand what Open Source is - http://xrl.us/bjn82
Shlomi, so what are you working on? Working on a new wiki about unit testing
fortunes in freecell? -- Ran Eilam
--- pod/perlopentut.pod.orig 2008-08-24 23:03:59.712932993 +0300
+++ pod/perlopentut.pod 2008-08-24 23:23:12.339272053 +0300
@@ -165,6 +165,32 @@
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 L<perlfunc/"system">'s C<system(@LIST)> notation.) This is safer and
+faster than executing a single argument pipe-command, but does not allow
+special shell constructs.
+
+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 md5sum:
+
+ open my $pipe, "|-", "md5sum"
+ or die "Could not execute md5sum";
+ print {$pipe} "Hi there!\n";
+ print {$pipe} "Non-random string.\n";
+ close($pipe);
+
=head2 The Minus File
Again following the lead of the standard shell utilities, Perl's
- Follow-Ups from:
-
Eric Wilhelm <scratchcomputing@gmail.com>
[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]