Perl触摸目录

0 perl

我是perl.Below的新手,是使用perl触摸目录的代码

#!/usr/bin/perl

# Populate the hashMap
# keys          -->  directories to clean
# attributes    -->  days to keep.



print "<-------------------------------------------------------->";
print " Touching of folders Started   ";
touch `/tmp/dir1`;
touch `/tmp/dir2`;
print " Touching of folders Ended   ";
print "<-------------------------------------------------------->";
Run Code Online (Sandbox Code Playgroud)

运行脚本时出现以下语法错误.请帮忙.

$ ./FeedServerHscript.sh
Backticks found where operator expected at /tmp/eCAS_Housekeep/Ecas_54.pl line 11, near "touch `/tmp/dir1`"
        (Do you need to predeclare touch?)
Backticks found where operator expected at /tmp/eCAS_Housekeep/Ecas_54.pl line 12, near "touch `/tmp/dir2`"
        (Do you need to predeclare touch?)
syntax error at /tmp/eCAS_Housekeep/Ecas_54.pl line 11, near "touch `/tmp/dir1`"
Execution of /tmp/eCAS_Housekeep/Ecas_54.pl aborted due to compilation errors.
Run Code Online (Sandbox Code Playgroud)

ser*_*sat 5

system如果您不想在变量中返回值,请使用命令而不是反引号.

print "<-------------------------------------------------------->";
print " Touching of folders Started   ";
system("touch /tmp/dir1");
system("touch /tmp/dir2");
print " Touching of folders Ended   ";
print "<-------------------------------------------------------->";
Run Code Online (Sandbox Code Playgroud)

像这样使用反引号:

my $dir2 = `touch /tmp/dir1`;
my $dir2 = `touch /tmp/dir2`;
Run Code Online (Sandbox Code Playgroud)

有关详细信息system,请参阅以下内容backtick:https: //stackoverflow.com/a/800105/4248931