Edits for the new information from the asker.
If you just want to process the contents of all those files, this should work:
@ARGV = qw<F1 f2 f3 f4>;
print "<XML>\n";
while ( my $line = <> ) {
print " $line";
}
print "</XML>\n";
Of course, you could just cat the files together if you cared as little about indentation as XML does--and bookend it with "\n" ... "\n".
Name of the current file will be in $ARGV
if you need it. Number of current record is in $.
( or via English: $NR
or $INPUT_LINE_NUMBER
)
Merge
If you want to merge files, they need to be sorted ( File::Sort ). And then you need to have a dedicated buffer to all the files you want to merge and scan for the lowest record based on the sorting scheme. If you choose that buffer, refresh it from that file, and process the buffer.
Those steps are:
- Pick first in concatenation order
- Refresh from respective file, flag if EOF
- Process record
I would create a Buffer
as well as BufferSet
class to encapsulate this functionality. The Buffer
knows how to offer up the current record when asked, and to refresh from its IO source, when chosen. The BufferSet
knows to look for next record from its list of Buffer objects and to handle the Buffer
objects. The BufferSet
object should definitely know the sorting order, and it might also handle the job of making sure that any buffer has been sorted.
You can use Class::Delegator to make the BufferSet behave like a straight IO object, if you wanted to do that.