任何人都可以指出我的错误
#!/usr/local/bin/perl
my $i;
for $i in {1..10}
do
system("touch file${i}");
done
我已经在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 "
即使在终端touch file{1..10}
上也不会创建file1,file2,... file10,而是会创建文件{1..10}。
谢谢。
答案 0 :(得分:3)
不确定您如何自学Perl,但是循环的语法错误。看来您在混淆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}");
}