Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Multiple file reading

by Anonymous Monk
on Jul 27, 2000 at 02:02 UTC ( #24587=note: print w/replies, xml ) Need Help??

in reply to Multiple file reading

Wow! that was very quick response. Sorry about the confusion.I moved to USA about a year ago. My English is not good! Anyway, This is a little modification on previous question. I have two different files, They have 1s, 0s,and xs. I want the new file to write the first element of file1 with first element of file2 , in order you know. Let's see, what.txt has this, xx110 and what1.txt has this, 001xx. I want, x0x0111x0x. First element of file1 with first element of file2 and so forth.You see what I mean. May be I am still not clear huh? Thank you very much for your responses though. Bye. Have a good day.

Replies are listed 'Best First'.
RE: Multiple file reading
by perlmonkey (Hermit) on Jul 27, 2000 at 07:27 UTC
    I think this is what you want:
    @a = split //, 'xx110'; @b = split //, '001xx'; splice @a, ++$i, 0, $_ or $i++ for(@b); print @a, "\n";
    Results: x0x0111x0x
    You just have to read in each line of your files, then split the characters into an array. The splice line is sort of tricky. It inserts each element of @b into @a, at the 1st, 3rd, 5th ... position of @a. I hope this helps. There may be another and better way to merge arrays, but I cant think of one right now.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://24587]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2018-06-23 15:15 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (125 votes). Check out past polls.