[英]why touch command is not working in perl?
Could anyone please point out my error 任何人都可以指出我的错误
#!/usr/local/bin/perl
my $i;
for $i in {1..10}
do
system("touch file${i}");
done
I have saved above in file.pl and did perl file.pl
and error popping up is 我已经在file.pl中保存了以上内容,并做了
perl file.pl
并且弹出了错误提示
Bareword found where operator expected at tr.pl line 4, near "$i in"
(Missing operator before in?)
syntax error at tr.pl line 4, near "$i in "
Even on terminal touch file{1..10}
doesn't create file1, file2, ...file10 instead it creates file{1..10}. 即使在终端
touch file{1..10}
也不会创建file1,file2,... file10,而是创建文件{1..10}。
Thanks in advance . 提前致谢 。
Not sure how you're teaching yourself Perl, but your syntax for the loop is wrong. 不知道您如何自学Perl,但是循环的语法是错误的。 It looks like you're confusing shell scripting with Perl programming.
似乎您在将Shell脚本与Perl编程混淆了。
#!/usr/local/bin/perl
# Always add these
use strict;
use warnings;
# Round parens for the "for" list.
# Curly braces to delimit the code block.
for my $i (1..10) {
system("touch file${i}");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.