Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
所以我有一个foreach循环:
foreach
foreach (1..10) { print "#", $t, "\n"; }
但我也有一个标量:
$number = 5;
我可以像这样从 1 数到标量吗?
foreach (1..$number) { print "#", $t, "\n"; }
当我这样做时,程序什么也不输出。我能做些什么来完成这项工作?
脚本:
#!/usr/bin/perl use strict; use warnings; my $number = 5; foreach (1..$number) { print "#$_\n"; }
或者
#!/usr/bin/perl use strict; use warnings; my $number = 5; print "#$_\n" for 1..$number;
输出:
#1 #2 #3 #4 #5