1 2 3 4 5 | while ( ) { # do something with the current input here } |
1 2 3 4 5 6 7 8 | my $i; do { # put values in @list here... ... $i = grep(/pattern/, @list); } until($i > 0); |
1 2 3 4 5 6 7 8 9 10 | for ($i=0; $i++; $i < 10) { # do something 10 times } $i=0; while ($i < 10) { # do something 10 times $i++; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | foreach (1..100) { # do something 100 times, $_ will be set to the current number print "Now on iteration $_\n"; } foreach (1..20,101..120) { # do something 40 times, $_ will be set to the current number } foreach my $counter (0..1) { # do something twice, $counter will be 0, then 1 } foreach my $i (0..1000) { next unless $i%5; # next if this number is a multiple of 5 print "$i is not a multiple of 5...\n"; next unless $i%7; # next if this number is a multiple of 7 print "$i is not a multiple of 7...\n"; next unless $i%12; # next is this number is a multiple of 12 # $i is now not a multiple of 12, 5, or 7 print "$i is a lucky, lucky number to have met you...\n"; } # here we use the Perl map operator to create a list of 100 even numbers # see chapter 5 for details on the map and grep operators foreach (map { $_ *= 2 } 0..99) { print "Even number: $_\n"; |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |