Home > Archive > PERL Modules > February 2007 > virtual file concatenation
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
virtual file concatenation
|
|
| xhoster@gmail.com 2007-02-19, 6:58 pm |
| When refactoring code to read from more than one file in sequence, I will
occasionally use somthing like this, which works but makes me
feel dirty:
open my $fh, "cat file1 file2 file3 |" or die $!;
while(<$fh> ) {
I'd rather virtually concatenate file handles, like this:
## $fh1 $fh2 $fh3 are already open read handles
my $fh= IO::Something->new($fh1,$fh2,$fh3);
while (<$fh> ) {
where $fh is an object of a class inheriting from IO::Handle (but probably
not from IO::S able, although that would be nice) which will read from
$fh1 until the end, then from $fh2, then from $fh3.
I've looked in CPAN but haven't seen anything, which kind of surprised me.
Is there something I've overlooked? If not, would this be a worthwhile
module?
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
| |
| John W. Krahn 2007-02-19, 6:58 pm |
| xhoster@gmail.com wrote:
> When refactoring code to read from more than one file in sequence, I will
> occasionally use somthing like this, which works but makes me
> feel dirty:
>
> open my $fh, "cat file1 file2 file3 |" or die $!;
> while(<$fh> ) {
@ARGV = qw/ file1 file2 file3 /;
while ( <> ) {
> I'd rather virtually concatenate file handles, like this:
>
> ## $fh1 $fh2 $fh3 are already open read handles
> my $fh= IO::Something->new($fh1,$fh2,$fh3);
> while (<$fh> ) {
for my $fh ( $fh1, $fh2, $fh3 ) {
while ( <$fh> ) {
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
|
|
|
|
|