Hello Dear and Wise Monks

In the code that concatenates of lines (a big thanks to dogz007 , see thread concatenation of lines from two different files ) , the lines concatenated are on two different lines instead of being on the same line

And I do not undertsand why, because chomp was used

Here is the first file

08:49:43;DAL11;08:10;08:30;08:30;08:39;08:47;08:47;08:50;;;;;05:03:00; +08:10;-187;;08:30;0;0;;;;;;;;

Here is the second file

DAL11;DAL12;DAL;B772;KATL;EGKK;22:05;1325;05:39;339

And here is the result

08:49:43;DAL11;08:10;08:30;08:30;08:39;08:47;08:47;08:50;;;;;05:03:00; +08:10;-187;;08:30;0;0;;;;;;;; DAL12;DAL;B772;KATL;EGKK;22:05;1325;05:39;339

I would have liked

08:49:43;DAL11;08:10;08:30;08:30;08:39;08:47;08:47;08:50;;;;;05:03:00; +08:10;-187;;08:30;0;0;;;;;;;;DAL12;DAL;B772;KATL;EGKK;22:05;1325;05:3 +9;339

And here is the code

#!/usr/bin/perl use strict; use warnings; use diagnostics; use Cwd; # display current working directory my $Current_Dir = getcwd; print STDOUT "the current directory is $Current_Dir\n"; # input files to work on my $file_1 = "$ARGV[0]"; my $file_2 = "$ARGV[1]"; my $outfile = "outfile_$file_1"; # open files open INFILE_1, '<', $file_1, or die "Can't open $file_1 : $!"; open INFILE_2, '<', $file_2, or die "Can't open ${file_2} : $!"; open OUTFILE, '>', $outfile, or die "Can't open $outfile : $!"; # create hash of aircraft specific data from file 2 my %aircraftID; while (my $line_2 = <INFILE_2>){ chomp($line_2); my @Elements_2 = split ';', $line_2; my $aircraft_id_2 = shift @Elements_2; $aircraftID{$aircraft_id_2} = \@Elements_2; } close INFILE_2; # read each line of file1 and look for aircraft while (my $line_1 = <INFILE_1>){ chomp($line_1); my @Elements_1 = split ';', $line_1; my $aircraft_id_1 = $Elements_1[1]; my $length_1 = @Elements_1; # monitor the process print STDOUT "the length is $length_1\n"; print STDOUT "The Table is @Elements_1\n"; # print the current line into the output file print OUTFILE "$line_1"; # if the line contains an aircraft ID, search for its data in file 2 if ($aircraft_id_1 && exists $aircraftID{$aircraft_id_1}) { print OUTFILE join(';',@{$aircraftID{$aircraft_id_1}}), "\n"; } else { print "\n" } } close INFILE_1; close OUTFILE;

In reply to chomp and concatenation of lines by steph_bow

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.