开发者

Debugging Perl variable interpolation

I have a problem with my variable setup. Part of this command is working, except the awk command. Is it the use of $2 in this case?

use strict;
use warnings;

my $cmd = qx(开发者_开发知识库df -h | awk '{print $2}');
print "Output:$cmd\n";


$2 is evaluated by perl into a variable. You need to escape it:

my $cmd = qx(df -h | awk '{print \$2}');

Update:

You may wish to check out Filesys::DiskSpace. Using perl native solutions is most often better than trying to use system calls and parsing input.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜