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));
- for example, there differences between
open(my $fh, $x)
,open(my $fh, '<', $x)
. there differences betweenopen(my $fh, "< $x")
,open(my $fh, '<', $x)
.
Comments
Post a Comment