Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Suggest a mnemonic for piped open

by Anonymous Monk
on Jan 30, 2012 at 10:28 UTC ( #950740=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello

Yet again, I find myself forgetting which way round to to write a piped open in perl. I have just written:

open my $sort_FH, '-|', 'sort | uniq > '. $sorted_out_file or die "Error starting sort process $!";

When I should have used '|-'.

Can anyone suggest a mnemonic to help remember which way around the pipe and minus symbols go?

Comment on Suggest a mnemonic for piped open
Select or Download Code
Re: Suggest a mnemonic for piped open
by choroba (Abbot) on Jan 30, 2012 at 10:41 UTC
    From the documentation:
    In the 2-arguments (and 1-argument) form one should replace dash ('-') with the command.
Re: Suggest a mnemonic for piped open
by ikegami (Pope) on Jan 30, 2012 at 12:12 UTC

    It's never clear, but it's a bit clearer with 2-arg version.

    open my $sort_FH, '| sort | uniq > '. $sorted_out_file

    In the 3-arg version, the command is replaced with "-".

    open my $sort_FH, '|-', 'sort | uniq > '. $sorted_out_file
Re: Suggest a mnemonic for piped open
by BrowserUk (Pope) on Jan 30, 2012 at 12:30 UTC

    Not particularly mnemonic, but it's my best effort of putting what I think, when writing or reading the constructs, into words ...

    When the pipe is on the way in to the command: '| command' it is supplying input to the command.

    When the pipe in on the way out from the command: 'command |' it is receiving output from the command.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

Re: Suggest a mnemonic for piped open
by BrowserUk (Pope) on Jan 30, 2012 at 13:08 UTC

    Another way of thinking about it that might work for you.

    Place an imaginary 'perl' the other side of the pipe from the command.

    Then perl '| command' becomes: perl supplying input to the command.

    And 'command |' perl becomes: the command suppying input to perl.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://950740]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (11)
As of 2014-10-22 16:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (119 votes), past polls