... I am not sure what I need to do to get around these. ... I need them to be global variables, so I define them outside of the WHILE loops. If you say that you see them as redundant can you tell me how to get around doing this?
Please understand that what I see as redundant is useless explicit initialization of a variable. In the case of
my $input_file = undef;
the assignment does exactly what is done by default; it is purely redundant.
Semantically erroneous statements like
my @files = undef;
are redundant in the present circumstances because the very next thing you do with these arrays (as far as I can see) is to assign them valid data, thus undoing the erroneous initialization. In other circumstances, the erroneous initialization may lead to a nasty bug.
... I need them to be global variables, so I define them outside of the WHILE loops.
Of course, you need to define lexical variables where you need to use them. On this note, you only use the @dt lexical within the scope of the if($firstline==1){ ... } statement block, so that's exactly where I would define it:
if($firstline==1){
...
my @dt = $header[0] =~ /(\d+)/g;
...
} else {
<IN> for 1..1
}
(Incidentally, the <IN> for 1..1 statement is needlessly involved: if you just want to read and discard one line, the simple <IN>; statement does the trick.)
Give a man a fish: <%-{-{-{-<
|