Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Perl 使用for循环打印_Perl_For Loop - Fatal编程技术网

Perl 使用for循环打印

Perl 使用for循环打印,perl,for-loop,Perl,For Loop,我想以特定的格式打印一份声明。 例如: 我得到的结果是 hello world flag = 1 flag = 2 flag = 3 flag = 4 我希望输出像这样 hello world flag = 1 hello world flag = 2 hello world flag = 3 hello world flag = 4 有人能帮我吗?试试: my $flag = 0; my $new_counter = 4; for ( my $i =0; $i le $

我想以特定的格式打印一份声明。 例如:

我得到的结果是

hello world
flag = 1 
flag = 2 
flag = 3 
flag = 4 
我希望输出像这样

hello world
flag = 1 
hello world
flag = 2 
hello world
flag = 3 
hello world
flag = 4 
有人能帮我吗?

试试:

my $flag = 0;

my $new_counter = 4;

for ( my $i =0; $i le $new_counter; $i++) {
    print "hello world\n";
    print "flag = $i \n";
}

解决方案是移动
打印“hello world\n”在for循环的
内。

您不知道如何将
打印“hello world\n”
放在for循环内。。。?另外,
le
是一个字符串运算符,您应该对0使用
打印“hello world\nflag=$\n”。。4;@tlp事实上我已经把程序缩短并发布了。主脚本是复杂的方式发布。但是我忘了编辑le操作符。感谢您的更新。对于我们一无所知的问题,我们无法提出解决方案。如果
“hello world\n”
是一个字符串,则可以将其移动并打印到其他位置,没有问题。我们可以开始猜测问题是什么,但那将是徒劳的,是对时间的巨大浪费。
my $flag = 0;

my $new_counter = 4;

for ( my $i =0; $i le $new_counter; $i++) {
    print "hello world\n";
    print "flag = $i \n";
}