Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re^3: reading N files

by graff (Chancellor)
on Jul 20, 2006 at 01:37 UTC ( #562487=note: print w/replies, xml ) Need Help??

in reply to Re^2: reading N files
in thread reading N files

So, if you happened to be on a *n*x box (or have a windows port of standard unix utilities), you could just do a shell command (that includes a perl one-liner):
# assuming N files are named in some systematic way, # and columns are separated by whitespace: paste file.* | perl -pe '($t)=(/^(\S+)/); s/\t$t//g;' > multi-column.f +ile
The unix "paste" command takes a list of file names and concatenates them "horizontally", line by line; for a list of input files (1..N), its default behavior replaces the newline with a tab for each line of files 1..N-1.

Assuming that all files in the set have the same series of values in the first column, the perl script removes all but the first occurrence of that value on each line. (If all these assumptions don't apply, then your approach of reading from a set of file handles in a loop is fine, of course.)

Replies are listed 'Best First'.
Re^4: reading N files
by gri6507 (Deacon) on Jul 20, 2006 at 12:24 UTC
    I didn't know about the paste command. I'll have to keep it in mind in the future. However, it would not have worked in my scenario. One of the problems is that that values in the first column may or may not be the same series, making the merging step a bit more difficult.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://562487]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2021-10-27 14:23 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (93 votes). Check out past polls.