in reply to How to eliminate duplicated code?
That said, given that the file is so small, it does make sense to read it only once and hold it all in memory for both uses:
(not tested, but should be close, if the OP code is really what you intended)my @arr; # no need to initialize (and in any case, "= ''" makes littl +e sense) my @hdr; open( F, "x.txt" ) or die $!; while (<F>) { chomp; my @flds = split /,/; push @array, join( ' ', @flds ); push @hdr, $flds[1]; } print join( '/', @hdr ), "\n"; print join( "\n", @array ), "\n";
|
|---|