[PATCH] Add open "|-" and open "-|" to perlopentut

--Boundary_(ID_Jtp68aYGhuypKELODgqF8w)
Content-type: text/plain; charset=us-ascii
Content-transfer-encoding: 7BIT
Content-disposition: inline

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

--Boundary_(ID_Jtp68aYGhuypKELODgqF8w)
Content-type: text/x-diff; charset="iso 8859-15";
 name=patch-perlopentut-list-pipes-1.diff
Content-transfer-encoding: 7BIT
Content-disposition: attachment; filename=patch-perlopentut-list-pipes-1.diff

--- 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

--Boundary_(ID_Jtp68aYGhuypKELODgqF8w)--
0
shlomif
8/24/2008 8:28:00 PM
perl.perl5.porters 47902 articles. 1 followers. Follow

8 Replies
551 Views

Similar Articles

[PageSpeed] 24

# 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'?  Also, the filehandle in a simple 
scalar $pipe does not need to be wrapped in a block when used as an 
argument to print.  The error message could probably stand to contain 
$! as well.

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?

Finally, should these examples be included *before* the references to 
IPC::Open2 and perlipc?

--Eric
-- 
"Beware of bugs in the above code; I have only proved it correct, not
tried it."
--Donald Knuth
---------------------------------------------------
    http://scratchcomputing.com
---------------------------------------------------
0
scratchcomputing
8/25/2008 1:03:34 AM
--Boundary_(ID_vixt/9l/orrpMIW/0SPorQ)
Content-type: text/plain; charset=iso-8859-1
Content-transfer-encoding: 7BIT
Content-disposition: inline

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

--Boundary_(ID_vixt/9l/orrpMIW/0SPorQ)
Content-type: text/x-diff; charset="iso 8859-15";
 name=patch-perlopentut-list-pipes-1.diff
Content-transfer-encoding: 7BIT
Content-disposition: attachment; filename=patch-perlopentut-list-pipes-1.diff

--- 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

--Boundary_(ID_vixt/9l/orrpMIW/0SPorQ)--
0
shlomif
8/25/2008 3:30:21 AM
--Boundary_(ID_X4RvMWklL2wUjzAvVIk1nA)
Content-type: text/plain; charset=iso-8859-6
Content-transfer-encoding: 7BIT
Content-disposition: inline

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

--Boundary_(ID_X4RvMWklL2wUjzAvVIk1nA)
Content-type: text/x-diff; charset="iso 8859-15";
 name=patch-perlopentut-list-pipes-1.diff
Content-transfer-encoding: 7BIT
Content-disposition: attachment; filename=patch-perlopentut-list-pipes-1.diff

--- 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

--Boundary_(ID_X4RvMWklL2wUjzAvVIk1nA)--
0
shlomif
9/23/2008 1:10:42 PM
On Tue, 23 Sep 2008, Shlomi Fish wrote:
> 
> 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?

I think it would be good to mention that the *list* form of piped open
is not supported on Windows (nor on MacOS or RiscOS, but those are
quite less common).

Cheers,
-Jan

0
jand
9/23/2008 3:04:43 PM
--Boundary_(ID_cqbELl0co+13zmaTvwB9fA)
Content-type: text/plain; charset=iso-8859-1
Content-transfer-encoding: 7BIT
Content-disposition: inline

On Tuesday 23 September 2008, Jan Dubois wrote:
> On Tue, 23 Sep 2008, Shlomi Fish wrote:
> > 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?
>
> I think it would be good to mention that the *list* form of piped open
> is not supported on Windows (nor on MacOS or RiscOS, but those are
> quite less common).
>

You are right. I've added it to the attached version of the patch.

BTW, can anyone tell me why open FH, '|-', @list, and open FH, '-|', @list are 
not supported on Windows?

Regards,

	Shlomi Fish

-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Rethinking CPAN - http://xrl.us/bjn7p

Shlomi, so what are you working on? Working on a new wiki about unit testing 
fortunes in freecell? -- Ran Eilam

--Boundary_(ID_cqbELl0co+13zmaTvwB9fA)
Content-type: text/x-diff; charset="iso 8859-15";
 name=patch-perlopentut-list-pipes-2.diff
Content-transfer-encoding: 7BIT
Content-disposition: attachment; filename=patch-perlopentut-list-pipes-2.diff

--- ./pod/perlopentut.pod.orig	2008-08-24 23:03:59.712932993 +0300
+++ ./pod/perlopentut.pod	2008-09-23 18:57:06.974823438 +0300
@@ -165,6 +165,33 @@
 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. (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

--Boundary_(ID_cqbELl0co+13zmaTvwB9fA)--
0
shlomif
9/23/2008 4:00:41 PM
On Tue, 23 Sep 2008, Shlomi Fish wrote:
> BTW, can anyone tell me why open FH, '|-', @list, and open FH, '-|', @list are
> not supported on Windows?

Because Nick Ing-Simmons didn't have the tuits to implement it:

    http://www.nntp.perl.org/group/perl.perl5.porters/2002/06/msg60897.html

It is not clear to me why you need to implement it using
pseudo-fork; it should be possible to do it using do_aspawn().

Paul Fenwick wanted to look into this, but I'm not sure he got
around to it either:

    http://www.nntp.perl.org/group/perl.perl5.porters/2007/07/msg126377.html

Cheers,
-Jan


0
jand
9/23/2008 11:02:55 PM
2008/9/23 Shlomi Fish <shlomif@iglu.org.il>:
> On Tuesday 23 September 2008, Jan Dubois wrote:
>> On Tue, 23 Sep 2008, Shlomi Fish wrote:
>> > 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?
>>
>> I think it would be good to mention that the *list* form of piped open
>> is not supported on Windows (nor on MacOS or RiscOS, but those are
>> quite less common).
>>
>
> You are right. I've added it to the attached version of the patch.

Thanks, applied as #34435. I've removed the inline L<> though. Some
POd renderers might insert extra text here that would make the
sentence obscure.
0
rgarciasuarez
9/27/2008 3:24:05 PM
On Saturday 27 September 2008, Rafael Garcia-Suarez wrote:
> 2008/9/23 Shlomi Fish <shlomif@iglu.org.il>:
> > On Tuesday 23 September 2008, Jan Dubois wrote:
> >> On Tue, 23 Sep 2008, Shlomi Fish wrote:
> >> > 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?
> >>
> >> I think it would be good to mention that the *list* form of piped open
> >> is not supported on Windows (nor on MacOS or RiscOS, but those are
> >> quite less common).
> >
> > You are right. I've added it to the attached version of the patch.
>
> Thanks, applied as #34435. I've removed the inline L<> though. Some
> POd renderers might insert extra text here that would make the
> sentence obscure.

Thanks!

Regards,

	Shlomi Fish

-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Parody on "The Fountainhead" - http://xrl.us/bjria

Shlomi, so what are you working on? Working on a new wiki about unit testing 
fortunes in freecell? -- Ran Eilam
0
shlomif
9/27/2008 5:49:50 PM
Reply:

Similar Artilces:

"Open", "Open in new window", "Open in new tab" are greyed-out after drag&drop operation
Name: Dmitriy Email: dadotivanovathotmaildotcom Product: Firefox Release Candidate Summary: "Open", "Open in new window", "Open in new tab" are greyed-out after drag&drop operation Comments: Steps to Reproduce: 1. Drag&drop a bookmark from the Bookmarks Menu or Bookmarks Toolbar to the Tab bar. 2. Right-click on any bookmark (from the same folder, if darged from Menu, or from the visible part of Bookmarks Toolbar) Result: "Open", "Open in new window", "Open in new tab" are greyed-out Browser Details: Moz...

Precedence of "where" ("of", "is", "will")?
Nobody on #perl6 today could answer this one. Is: Str | Int where { $_ } the same as: (Str | Int) where { $_ } or: Str | (Int where { $_ }) ? Followup questions, Mr. President: What kind of operators are "where", "of", "is", and "will"? Is there a reason that S03 doesn't list them? What are their precedence(s)? -- Chip Salzenberg - a.k.a. - <chip@pobox.com> Open Source is not an excuse to write fun code then leave the actual work to others. Chip Salzenberg writes: &...

.ALLCOL("%COLUMN%", " ", ", ", ", ")
Do you know anyway for me to exclude a subset of columns returned by this function. We have two columns (rec_user and rec_datetime) which are in all of our tables, but when generating triggers I want automatically generate a script which does not include those two columns but does include all other columns in that table. Bruce I should add that I am using PD 9.0.0.580. Bruce "Bruce Lamb" <lamb.bruce@mayo.edu> wrote in message news:6HgI315nCHA.155@forums.sybase.com... > Do you know anyway for me to exclude a subset of columns returned by this > function. ...

Old charts: add "open" and "all" status
Is there an easy way to add these 2 values in the code for the old charts ? Using "new charts" is quite buggy so far, and above is the only thing I need: being able to see what is open versus what is closed and compare with total. -- View this message in context: http://www.nabble.com/Old-charts%3A-add-%22open%22-and-%22all%22-status-tf1967127.html#a5398700 Sent from the Bugzilla - Users forum at Nabble.com. ...

quotes, quotes, quotes...
I am getting this error and I know what is causing it, but I have no idea how to fix it, any help would be great. The script steps through the /var/log/messages file on a linux server and puts The entries into a mysql database. However when it gets to the 'hlt' line in the messages file it just barfs. The single quotes are freaking it out. I know about quotes but not how to use in this situation. Thanks, Paul Error: May 27 17:53:00 localhost kernel: Checking 'hlt' instruction... OK. <----- doesn't like this in the messages file DBD::mysql::st exec...

Old Emails "Transfer Failed" already "Delivered" and "Opened"
I have had this happen a couple times in the last several months, to different users in different PO's. A user will receive undeliverable email messages bounce, but they sent the email months ago and this is the first negative response. The sent items show the originals as delivered and opened. One of the entries though has "Transfer Failed" for a PO we don't have anymore it's been removed from the domain. Correct me if I'm wrong but "Transferred" means through the GWIA and "Delivered" is not. So I guess the messages were sent thro...

same "+" toolbar button for "open new tab" and "page Zoom"
How do I find which "toolbar customize" button icon has been put by which add-on, or was it built into basic ff? I am finding exactly same, identical "+" toolbar button for "open new tab" and also for "page Zoom". I got them from "customize" icon set. Whom to tell to make each button icon slight different. Are these built into ff, or some add-on might have put it. Thanks. -- Rawat On 9/29/2012 1:12 PM, V S Rawat gmoz wrote: > How do I find which "toolbar customize" button icon has been put by > which add...

Printer status "Opening" "not ready"
--____DOGFUUEXVKYXBLIDPYVX____ Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline; modification-date="Fri, 1 Mar 2007 16:45:33 +0000" NW6.5.5 On Tuesday our server with Iprint hit 100% utilisation and stuck there. ( = don't know why ) so we had to power cycle the system. It came back up cleanly with no apparent problems, until we tried to = print. Nothing would work. I unloaded NDPSM and reloaded it and things looked ok.. But ever since, printers seem to be randomly showing in windows as = ...

"To" and "From" missing
When I print emails, the words "To" and "From" are blank, even though the "To" name and "From name (addresser, addressee) do show up. This is not a problem for other users on my system. Suggestions In mailbox right click, view. On the message window, right click and choose print options. Make sure print header is checked. -- Barry Merchant NSC Volunteer SysOp *** no email unless requested please!! *** > In mailbox right click, view. On the message window, right click and > choose print options. Make sure prin...

replace the "." with a ","
Oi.... I need to build a small programm in ASP.NET and chose to use C# for it.Now i got everything working but there's one little problem.the first textbox is a double. I need to make it so that when someone enters a "." then it gets replaced by a ","any ideas?Ghan  string blah = "4.2.2.2";blah = blah.Replace(".", ",");Ryan Ryan OlshanASPInsider | Microsoft MVP, ASP.NEThttp://ryanolshan.comHow to ask a question...

"-" not "_"
I wrote a SQL statement in the data tab. I wrote a bunch of alaises as example ' word-type ' but when I hit the layout tab it converts the "-" to "_". So now my field name is ' word_type '. Is there any way to prevent this? CardGunner Don' use a hypen ( - ).  It isn't a valid character for column names.   See http://searchsqlserver.techtarget.com/expert/KnowledgebaseAnswer/0,289625,sid87_gci1188931,00.html   Here's an excerpt about column names: Letters as defined in the Unicode Standard 2.0 Decimal numbers from either B...

Replacing "\\" with "\"
Hi all I'm getting this value from a CheckBoxList control - a location of file, i have to remove "\\" and replace it with "\" and pass it to Query, how to do it, i tried with Replace, but coud'nt suceed. "\\\\Blaze10xp\\BLZ_SFS_07\\Sample Excel Files\\Excel Files\\report2.xls" thank's in advance - Prakash.C you tried Replace like this? string newstring = oldstring.Replace(@"\\",@"\");Plese, do not forget to click "Mark as Answer" on the post that helped you. Thanx!My blog: Scenes From A Developer Memory yes i tr...

"Me" is better than "You"
Yes I know, strings are frozen. But let me talk about it, I really can't get through the idea of a PC talkin to me. I consider my PC as an extension of myself, not a dumb companion who addresses Me as You. Yes there are times when I get angry with Him while I work and get wrong calculations etc.., but it really is my fault, Me using wrong istructions and eventually wanting to find someone else to blame, but it's Me. And yes, I consider Thunderbird my mail program, reading my mail on my PC as Me. So I personally like to have Me in the header bar as a compact address ...

Using "+" or "||"
Using SQLAnywhere 5.5.04, I've gotten into the habit of using "||" in ISQL to indicate a string concatenation. I needed to paste my SQL statement into the PowerBuilder script painter for some embedded SQL, and PB didn't like the "||" very much at all. I changed it to "+" and it seems to be ok. Do these two operators indicate ~exactly~ the same thing? moin, afaik these two's are not the same! if you're using "||" and any term is NULL then in the resultstring the term will be ignored if you use "+" then the resu...

Web resources about - [PATCH] Add open "|-" and open "-|" to perlopentut - perl.perl5.porters

Resources last updated: 12/19/2015 2:28:55 PM