How do I create 6 (six) temp files in perl and get their names for calls to `system())?
I want to optimize this pseudo code:
my $TEMP0 = new File::Temp( UNLINK => 0 );
system("PROGRAM0 --output $TEMP0");
my $TEMP1 = new File::Temp( UNLINK => 0 );
system("PROGRAM1 --input $TEMP0 --output $TEMP1");
my $TEMP2 = new File::Temp( UNLINK => 0 );
system("PROGRAM2 --input $TEMP0 --output $TEMP2");
my $TEMP3 = new File::Temp( UNLINK => 0 );
system("PROGRAM3 --input $TEMP1 $TEMP2 --output $TEMP3");
my $TEMP4 = new File::Temp( UNLINK => 0 );
system("PROGRAM4 --input $TEMP3 --output $TEMP4");
my $TEMP5 = new File::Temp( UNLINK => 0 );
system("PROGRAM4 --input $TEMP4 --output $TEMP5");
and at the end unlink all of the tempfiles:
unlink($TEMP0);
unlink($TEMP1);
unlink($TEMP2);
unlink($TEMP3);
unlink($TEMP4);
unlink($TEMP5);
You can use map with a range to generate the tempfiles. eg.
As there isn’t a set pattern in how the programs are called, it seems reasonable to keep them as separate calls to system.