Perl で配列から特定の要素のみを抽出する
#!/usr/bin/env perl my @numbers = (0, 1, 2, 3, 4, 5); my ($zero, $one, $two, $three, $four, $five) = @numbers; printf("%d, %d, %d, %d, %d, %d\n", $zero, $one, $two, $three, $four, $five); my ($this_is_one, $this_is_three, $this_is_five) = @numbers[1, 3, 5]; printf("%d, %d, %d\n", $this_is_one, $this_is_three, $this_is_five); my (undef, undef, $this_is_two, undef, $this_is_four, undef) = @numbers; printf("%d, %d\n", $this_is_two, $this_is_four);
実行結果
0, 1, 2, 3, 4, 5 1, 3, 5 2, 4