Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^4: Two Column Data

by PilotinControl (Pilgrim)
on May 11, 2015 at 19:54 UTC ( [id://1126340]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Two Column Data
in thread Two Column Data

The desired output should be this:
=====================
TRACK 1 | TRACK 2
=====================
B&O 101 | CSXT 1001
=====================
The data from File 1 needs to be in column 1 and the data from File 2 needs to be in column 2

Replies are listed 'Best First'.
Re^5: Two Column Data
by Laurent_R (Canon) on May 11, 2015 at 20:12 UTC
    OK, here is one way to do it:
    print "=====================================\n"); print "| INBOUND TRACK 1 | INBOUND TRACK 2 |\n"); print "=====================================\n"); open my $IN1, "<", "inbndtrk1.txt" or die "could not open inbndtrk1.tx +t" ; open my $IN2, "<", "inbndtrk2.txt" or die "could not open inbndtrk2.tx +t" ; while (my $in1 = <$IN1>) { chomp $in1; $in1 = s/:/ /; my $in2 = <$IN2>; $in2 = s/:/ /; print "$in1|$in2"; }
    Note that you have a slight discrepancy between the header and the data: your code for the header uses three "|" symbols, but the output result that you are looking for does not. I'll leave it to you to sort out what you really want, but feel free to ask if you encounter any difficulty, or if you don't understand something from the above code. Also note that this is untested, as I have not real test data.

    Update: Oops, stupid error on my part, thanks to AnomalousMonk for pointing out. The loop code should be:

    while (my $in1 = <$IN1>) { chomp $in1; $in1 =~ s/:/ /; my $in2 = <$IN2>; $in2 =~ s/:/ /; print "$in1|$in2"; }

    Je suis Charlie.

      Does not show anything even when there is data in the files...all it shows is the "| |" when executed.

        $in1 = s/:/ /; should be  $in1 =~ s/:/ /; (= vice =~), and likewise for  $in2 = s/:/ /;

        Update: Or, in a single statement (untested):
            s/:/ / for $in1, $in2;


        Give a man a fish:  <%-(-(-(-<

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-23 20:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found