Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: Use 2 files and print each line of each one side-by-side

by Util (Priest)
on Feb 19, 2014 at 03:40 UTC ( #1075417=note: print w/replies, xml ) Need Help??


in reply to Re: Use 2 files and print each line of each one side-by-side
in thread Use 2 files and print each line of each one side-by-side

Also for fun, a Perl 6 version.
Note that this only works for files of the same length, because Z terminates (without error) when the shorter list ends.

use v6; sub MAIN ( $in_path1, $in_path2, $out_path = 'CONCATENATED_FILES' ) { my $in1 = open $in_path1, :r; my $in2 = open $in_path2, :r; my $out = open $out_path, :w; for $in1.lines Z $in2.lines -> $line1, $line2 { $out.say: "$line1\t$line2"; } .close for $out, $in1, $in2; }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2020-05-30 11:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (171 votes). Check out past polls.

    Notices?