こんな感じでできたのでメモ。
ソースコード
- filehandle.pl
#!/usr/bin/env perl use strict; use warnings; my @array = (1,2,3,4,5,6,7,8,9,10); foreach my $item (@array) { no strict "refs"; my $fh = "OUT${item}"; open (${$fh}, ">", "${item}.txt"); print({${$fh}} "$item\n"); close(${$fh}); } __END__
実行結果
$./filehandle.pl $ ls 1.txt 10.txt 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt 9.txt filehandle.pl $ cat *.txt 1 10 2 3 4 5 6 7 8 9