# ループ処理 my $i = 0; while($i < 10){ print "i = $i\n"; $i++; } [/perl] vagrant@vagrant-ubuntu-trusty-64:~/app$ perl hello.pl i = 0 i = 1 i = 2 i = 3 i = 4 i = 5 i = 6 i = 7 i = 8 i = 9 for文 [perl] for(my $i = 0; $i < 10; $i++){ print "i = $i\n"; } [/perl] おおおおおお、foreachが可笑しなことになってる。。 [perl] my @colors = qw(red green blue orange pink); foreach my $color (@colors){ print "color = $color\n"; } [/perl] vagrant@vagrant-ubuntu-trusty-64:~/app$ perl hello.pl color = red color = green color = blue color = orange color = pink ナニコレ? [perl] my @colors = qw(red green blue orange pink); foreach (@colors){ print "color = $_\n"; } [/perl] vagrant@vagrant-ubuntu-trusty-64:~/app$ perl hello.pl color = red color = green color = blue color = orange color = pink これは。。。 [perl] my %sales = ("tanaka"=>150, "suzuki"=>300, "ohira"=>200); foreach my $key (keys(%sales)){ print "sales for $key in $sales{$key}\n" }
vagrant@vagrant-ubuntu-trusty-64:~/app$ perl hello.pl
sales for tanaka in 150
sales for suzuki in 300
sales for ohira in 200