파일 핸들을 포함하는 해시 참조를 설정 중입니다.Perl에서 열 수있는 파일 핸들 수에 제한이 있습니까?
$ cut -f4 myFile | sort | uniq
id-0001
id-0002
...
: 나는 식별자의 목록을 얻으려면 GNU 기본 유틸리티를 사용
col1 col2 col3 id-0008 col5
col1 col2 col3 id-0002 col5
col1 col2 col3 id-0001 col5
col1 col2 col3 id-0001 col5
col1 col2 col3 id-0007 col5
...
col1 col2 col3 id-0003 col5
:
내 입력 파일의 네 번째 열은 내가 파일 핸들의 목적지 이름을 사용하고 식별자 필드를 포함
이 열에 1024 개가 넘는 고유 식별자가있을 수 있으며 각 식별자에 대해 파일 핸들을 열고 해당 핸들을 해시 참조에 넣어야합니다. 펄의 상한은 해시 참조 I 열 수있는 파일 핸들 또는 저장소의 수에 거기에
opening handle to: /foo/bar/baz/id-0001/coordinates.bed
opening handle to: /foo/bar/baz/id-0002/coordinates.bed
...
opening handle to: /foo/bar/baz/id-1022/coordinates.bed
could not open handle to /foo/bar/baz/id-1022/coordinates.bed
0
6144 at ./process.pl line 66.
:
my $fhsRef;
my $fileOfInterest = "/foo/bar/fileOfInterest.txt";
openFileHandles($fileOfInterest);
closeFileHandles();
sub openFileHandles {
my ($fn) = @_;
print STDERR "getting set names... (this may take a few moments)\n";
my $resultStr = `cut -f4 $fn | sort | uniq`;
chomp($resultStr);
my @setNames = split("\n", $resultStr);
foreach my $setName (@setNames) {
my $destDir = "$rootDir/$subDir/$setName"; if (! -d $destDir) { mkpath $destDir; }
my $destFn = "$destDir/coordinates.bed";
local *FILE;
print STDERR "opening handle to: $destFn\n";
open (FILE, "> $destFn") or die "could not open handle to $destFn\n$!\n";
$fhsRef->{$setName}->{fh} = *FILE;
$fhsRef->{$setName}->{fn} = $destFn;
}
}
sub closeFileHandles {
foreach my $setName (keys %{$fhsRef}) {
print STDERR "closing handle to: ".$fhsRef->{$setName}->{fn}."\n";
close $fhsRef->{$setName}->{fh};
}
}
문제는 내 코드 id-1022
의 동등한에서 죽어 가고 있다는 것입니다 ? 아니면 다른 곳에서 다른 실수를 저질렀습니까?
Perl은 제한을 두지 않지만 사용자의 OS는 확실하게 않습니다. (1024, STDIN + STDOUT + STDERR + 1021) 제한은 구성 가능할 수 있습니다. 그건 그렇고,'$!'이 아니라'$!'를 출력해야합니다. – ikegami
네 말이 맞아, 오타. –
http://perldoc.perl.org/FileCache.html FileCache는 열린 파일에 대한 OS 제한을 초과 할 수 있도록하는 표준 모듈입니다. – d5e5