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.
精彩评论