in reply to Re^2: Merging files
in thread Merging files
I think you should keep track of which filehandle is still open, and read it only in that case. And I am always wary of while(1) loops. But its probably just me ;--)
#!/usr/bin/perl -w use strict; use Fatal qw(open close); my @files= @ARGV; my %fh; # file => file handle foreach my $file (@files) { open( my $fh, '<', $file); $fh{$file}= $fh; } while( keys %fh) { foreach my $file (@files) { if( exists $fh{$file}) { my $fh= $fh{$file}; if( defined( my $line= <$fh>)) { chomp $line; print $line;} # regular line else { delete $fh{$file}; } # eof reached for this file } } print "\n"; # end of line for all files }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Merging files
by sk (Curate) on Apr 11, 2005 at 09:23 UTC | |
|
Re^4: Merging files
by cazz (Pilgrim) on Apr 11, 2005 at 14:26 UTC |