Skip to content

Commit ff69616

Browse files
committed
Add the equivalent of backticks - capture stdout.
1 parent 861648f commit ff69616

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

doc/Language/5to6-nutshell.pod

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,6 +1097,22 @@ e.g.:
10971097
my @lines = "test-file".IO.slurp.split(/\n/);
10981098
say @lines.elems; #-> 4
10991099
1100+
=head2 Trapping the standard output of executables.
1101+
1102+
Whereas in Perl 5 you would do:
1103+
1104+
my $arg = 'Hello';
1105+
my $captured = `echo "$arg"`;
1106+
my $captured = qx(echo "$arg");
1107+
1108+
In Perl 6, you can do:
1109+
1110+
my $arg = 'Hello';
1111+
my $captured = qq:x(echo "{$arg}");
1112+
1113+
Beware of interpolating strings with special shell characters! (Which is a
1114+
problem in Perl 5 as well).
1115+
11001116
=head1 Environment variables
11011117
11021118
=head2 Perl module library path

0 commit comments

Comments
 (0)