OK, I probably didn't phrase that very well. But can I open more than one
filename to a single filehandle, or alternatively use more than one
filehandle in a while loop?
What I want to do is something like this:
open FILEHANDLE "file1" + "file2";
while (<FILEHANDLE>) {do stuff}
I know I can use ARGV, but in the situation I'm trying to use it, it behaves
differently to a filehandle generated with 'open'. I'm trying to get batches
of a fixed number of records to process and want to load a fixed number of
records into an array (from two files, one after the other). Then if the
final array value contains something, I want to process that batch (since
I've got enough records), otherwise it means that I've run out of data
before having enough for a full batch, and want to save that data for later
analysis.
Test code that duplicates the problem:
@ARGV = qw(test1 test2);
for $i(0..9) {$array[$i] = <>}
print @array;
Unless there are an exact multiple of 10 lines in file1 + file2, this
freezes up when it runs out of data (I guess because it's waiting for the
remaining data to finish the for loop). However with a filehandle from
'open', it does what I want (except of course I can only use one file) and
completes the for loop, putting (I think) undef in the remaining places.
I've found a couple of workarounds, but really would like to use something
like the multiple file handling behaviour of ARGV with a conventionally
'open'ed filehandle - can it be done please?
Thanks
Mark C
> -----Original Message-----
> From: Jeff 'japhy' Pinyan [mailto:[EMAIL PROTECTED]]
> Sent: 02 July 2001 16:53
> To: mark crowe (JIC)
> Cc: [EMAIL PROTECTED]
> Subject: Re: Multiple files in a filehandle
>
>
> On Jul 2, mark crowe (JIC) said:
>
> >Please can anyone tell me if there is a way to open multiple
> files to a
> >single filehandle, or somehow carry out something
> equivalent. I can do it by
> >putting the filenames into @ARGV and then doing a while (<>)
> {loop}, but I'd
> >like to use a specific filehandle name.
>
> There *IS* a specific filehandle being used -- ARGV.