perl - difference between pipe and pipe- while writing to a program -


different ways write data program

way1:

open(writeme, "| program arguments"); print writeme "data\n"; close(writeme); 

way2:

open(writeme, "|-", "program arguments"); print writeme "data\n"; close(writeme); 

please explain, difference between them?

there no difference.

there differences between 2 forms in other cases[1], there no differences example given.

however, there 1 benefit of using three-argument form of 1 can take advantage when using function of open. open, system, run program directly (rather invoking shell execute it) when command passed list of multiple values. means following avoids invoking shell:

open(writeme, "|-", "program", "arguments"); 

there many benefits avoiding shell middle-man. primary benefit lack of need convert variables shell literals. in other words,

open(writeme, "|-", "program", "--", $file); 

is simple way of doing

use shell::stringquote qw( shell_quote ); open(writeme, "| ".shell_quote("program", "--", $file)); 

  1. for example, there differences between open(my $fh, $x) , open(my $fh, '<', $x). there differences between open(my $fh, "< $x") , open(my $fh, '<', $x).

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -