Click here to get back home

virtual file concatenation

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
virtual file concatenation xhoster 02-19-2007
Posted by xhoster on February 19, 2007, 4:54 pm
Please log in for more thread options


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::Seekable, 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

Posted by John W. Krahn on February 19, 2007, 6:47 pm
Please log in for more thread options


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

Similar ThreadsPosted
can apache::filter work with virtual location? July 28, 2007, 10:36 pm
install HTML::Template - Problem reading cache file / Bad file number July 24, 2004, 7:55 pm
Reading contents of an excel file from a test file May 15, 2007, 2:49 am
A do-file location: how the code inside that do-file find it? January 20, 2008, 12:32 am
DBD:mysql doesn't read mysql option file /etc/my.cnf file January 27, 2005, 11:19 pm
Win32::File August 29, 2004, 9:08 pm
SGI::FAM and File::PathConvert June 14, 2005, 10:58 am
file upload January 5, 2006, 7:00 am
How to read an IFO file ? February 25, 2006, 3:12 pm
How to get the length of wav file? May 16, 2006, 1:01 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap