How do I echo string with bash command more in Perl?
This is what I tried:
my $s = "s" x 1000;
my $r = `echo $s |more`;
But it doesn't work, my prog开发者_开发知识库ram exits directly...
It does not work in your example, because you never print $r
. The output is captured in the variable $r
. By using system()
instead, you can see the output printed to STDOUT, but then you cannot use the output as you (probably) expected.
Just do:
print $r;
Update: I changed say
to print
, since "echo" already gives you a newline.
To escape shell meta characters, as mentioned in the comments, you can use quotemeta.
You should also be aware that | more
has no effect when capturing output from the shell into a variable. The process is simply: echo | more | $r
, and you might as well skip more
.
try with the system() command :
my $s = "s" x 1000;
my $r = system("echo $s |more");
will display all your 's', and in $r
you will have the result (0 in this case) of the command.
精彩评论