Это должно работать нормально, просто держите @tempfiles
, пока файлы не будут связаны.
my @tempfiles = map {
File::Temp->new( UNLINK => 1, use_exlock => 0 );
} 0..5;
system("PROGRAM0 --output $tempfile[0]");
system("PROGRAM1 --input $tempfile[0] --output $tempfile[1]");
system("PROGRAM2 --input $tempfile[0] --output $tempfile[2]");
system("PROGRAM3 --input $tempfile[1] $tempfile[2] --output $tempfile[3]");
system("PROGRAM4 --input $tempfile[3] --output $tempfile[4]");
system("PROGRAM4 --input $tempfile[4] --output $tempfile[5]");
...
undef @tempfiles; # unlink all
Если на самом деле более логично было бы связать файлы с каким-либо внутренним именем, напишите это так:
my %tempfiles = map{
$_ => File::Temp->new( UNLINK => 1, use_exlock => 0 );
} qw'zero one two three four five';
system("PROGRAM0 --output $tempfile{zero}");
system("PROGRAM1 --input $tempfile{zero} --output $tempfile{one}");
system("PROGRAM2 --input $tempfile{zero} --output $tempfile{two}");
system("PROGRAM3 --input $tempfile{one} $tempfile{two} --output $tempfile{three}");
system("PROGRAM4 --input $tempfile{three} --output $tempfile{four}");
system("PROGRAM4 --input $tempfile{four} --output $tempfile{five}");
...
undef %tempfiles; # unlink all