in reply to My sub does not work twice
For what value of "doesn't work"?
Note that you should not be using our to "declare" variables. Use my instead and make the declarations as local to the variables' use as possible.
use strict; use warnings; open OUT, '>', 'input.txt'; print OUT <<OUT; contents of input.txt OUT close OUT; sub Job_selection{ my $select_job = shift; open (my $filehandle_in, "<", "input.txt") || die "Can't read inpu +t.txt: $!"; open (my $filehandle_out, ">", "output_$select_job.txt") || die "C +an't write output_$select_job.txt: $!"; print $filehandle_out (<$filehandle_in>); close $filehandle_in; close $filehandle_out; } Job_selection("1"); Job_selection("2");
generates files called 'output_1.txt' and 'output_2.txt' containing the text 'contents of input.txt' as I would expect. What would you expect?
|
|---|