How to do multiple files at once? 
Author Message
 How to do multiple files at once?

How would you do this in Perl?

I have an unknown number of files containing sorted data.  I want to
open them all at once and merge them into one sorted output.  Unfortunately,
Perl doesn't have the concept of arrays of file handles.

Would the best way be to construct file handles on the fly and use eval
to effect them?

                        Thanks,
                                Tim



Thu, 11 Sep 1997 01:11:43 GMT  
 How to do multiple files at once?


Quote:
>How would you do this in Perl?

>I have an unknown number of files containing sorted data.  I want to
>open them all at once and merge them into one sorted output.  Unfortunately,
>Perl doesn't have the concept of arrays of file handles.

Close enough.  To operate of filehandle number $n, just do

open($n, ...);
$foo = <$n>;
close($n):

It's easy to do more than one "array" of filehandles, since a filehandle name
can be any old string:

$fh = "FH$n";
open($fh, ...);
$foo = <$fh>;
close($fh);

Sometimes you just use the string directly, but not inside of <>.

Quote:
>Would the best way be to construct file handles on the fly and use eval
>to effect them?

You don't need eval for this.

--
<J Q B>



Thu, 11 Sep 1997 12:58:17 GMT  
 How to do multiple files at once?
Actually, you can just use

    print { $files[$i } "text";

Perl support arrays of strings just fine, and a string can represent
a filehandle.  

I would be nice to have a more standardly used sysopen() function so
you could do:

    $fh = sysopen($pathname, O_CREAT | O_TRUNC | O_WRONLY | O_EXCL,
            S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);

It's actually not to hard to rig up.  Something like this:

    sub sysopen {

        return FileHandle->new_from_fd($fd, put the mode here);
    }

In comp.lang.perl,



:>How would you do this in Perl?
:>
:>I have an unknown number of files containing sorted data.  I want to
:>open them all at once and merge them into one sorted output.  Unfortunately,
:>Perl doesn't have the concept of arrays of file handles.
:
:Close enough.  To operate of filehandle number $n, just do
:
:open($n, ...);
:$foo = <$n>;
:close($n):
:
:It's easy to do more than one "array" of filehandles, since a filehandle name
:can be any old string:
:
:$fh = "FH$n";
:open($fh, ...);
:$foo = <$fh>;
:close($fh);
:
:Sometimes you just use the string directly, but not inside of <>.
:
:>Would the best way be to construct file handles on the fly and use eval
:>to effect them?
:
:You don't need eval for this.
:
:--
:<J Q B>
:

--

sv_magic(sv, Nullsv, 'B', Nullch, 0);     /* deep magic */
    --Larry Wall, from util.c in the v5.0 perl distribution



Wed, 17 Sep 1997 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. How to upload multiple graphic files at once ?

2. How to upload multiple graphic files at once ?

3. Possible Bug: Multiple DBM Files at once

4. Doing two tasks at once

5. Multiple dbmopen()'s at once (perl4)

6. comment out multiple lines at once

7. Retrieving multiple hash elements at once

8. undef()-fing multiple items at once

9. Multiple edits, multiple files

10. Get directory only once and put it in array with File::Find

11. File I/O: want to compare two or more lines @ once

12. in-place file editing once script started

 

 
Powered by phpBB® Forum Software