Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Two Column Data

by edimusrex (Monk)
on May 11, 2015 at 19:09 UTC ( [id://1126331]=note: print w/replies, xml ) Need Help??


in reply to Two Column Data

I don't know if this will help or not but this is my approach assuming the files are relatively small in size and that the lines in each file are equal to each other

#!/usr/bin/perl use warnings; use strict; open my $a, "<", "file1.txt" or die "Failed to open File : $!"; open my $b, "<", "file2.txt" or die "Failed to open File : $!"; open my $out, ">", "output.txt" or die "Failed to open File : $!"; chomp(my @file1=<$a>); chomp(my @file2=<$b>); close $a; close $b; my $max = @file1; my $min = 0; while ($min < $max) { print $min."\n"; print $out "$file1[$min] : $file2[$min]\n"; $min++; } close $out;

Of course with the print $out statement you can use any separator you chose (chose a colon). Hope it helps

Replies are listed 'Best First'.
Re^2: Two Column Data
by PilotinControl (Pilgrim) on May 11, 2015 at 19:31 UTC

    My apologies...the output needs to be sent to STDOUT not to another file. I'll give you a vote for another approach which I see I will be using here shortly.

      Ok, try this then

      #!/usr/bin/perl use warnings; use strict; open my $a, "<", "file1.txt" or die "Failed to open File : $!"; open my $b, "<", "file2.txt" or die "Failed to open File : $!"; chomp(my @file1=<$a>); chomp(my @file2=<$b>); close $a; close $b; my $max = @file1; my $min = 0; while ($min < $max) { print "$file1[$min] : $file2[$min]\n"; $min++; }

      That should print to standard out

        That works fine....however the data needs to be split and have the : removed.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2024-04-23 14:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found