[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]
Re: [PATCH] Add open "|-" and open "-|" to perlopentut
Hi all!
It's been nearly a month since there was activity on this patch. Should I
modify it further, or can it be applied as is?
Regards,
-- Shlomi Fish
On Monday 25 August 2008, Shlomi Fish wrote:
> On Monday 25 August 2008, Eric Wilhelm wrote:
> > # from Shlomi Fish
> >
> > # on Sunday 24 August 2008 13:28:
> > >This patch documents open "|-" and open "-|" in perlopentut.
> >
> > Perhaps it should follow the practice of single quoting non-interpolated
> > strings like '|-' and 'fortune'?
>
> Fixed in my copy.
>
> > Also, the filehandle in a simple
> > scalar $pipe does not need to be wrapped in a block when used as an
> > argument to print.
>
> But:
>
> {{{{{{{{{{
> print $pipe "Hi there!\n"
> }}}}}}}}}}
>
> is not recommended by PBP and I agree that the $pipe does not really stand
> out there.
>
> > The error message could probably stand to contain
> > $! as well.
>
> Fixed in my copy.
>
> > I find the md5sum example not very illustrative (because md5sum will
> > just print the result to stdout.) What about simply restating the
> > aforementioned lpr and netstat examples?
>
> I converted the '|-' example to "lpr".
>
> > Finally, should these examples be included *before* the references to
> > IPC::Open2 and perlipc?
>
> Don't know.
>
> > --Eric
>
> New patch attached.
>
> Regards,
>
> Shlomi Fish
>
>
> -----------------------------------------------------------------
> Shlomi Fish http://www.shlomifish.org/
> "The Human Hacking Field Guide" - http://xrl.us/bjn8q
>
> Shlomi, so what are you working on? Working on a new wiki about unit
> testing fortunes in freecell? -- Ran Eilam
-----------------------------------------------------------------
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-25 06:27:23.367929248 +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 $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
- Follow-Ups from:
-
"Jan Dubois" <jand@activestate.com>
[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]