Hi Perlmonks,

I am trying to get rid of the last column in the output file. Though, I was successful in getting rid of the column, the columnheader still is present. I tried different things, but, I wasn't able to get the desired output. I am using three input files. The output file will contain the matching entries from the first column of the input files. The header for output file is the same as the input files except the last column. All the input files have 6 columns (so, my output file should have only 5 columns).

#!/usr/bin/perl -w use strict; use warnings; use Text::CSV_XS; open (my $FILE1, '<', "fileX.csv") or die "cannot open file1 $!\n"; open (my $FILE2, '<', "fileY.csv") or die "cannot open file2 $!\n"; open (my $FILE3, '<', "fileZ.csv") or die "cannot open file3 $!\n"; open (my $FILE4, '>', "Outputfile.csv") or die "cannot open file4 $!\n +"; my $csv = Text::CSV_XS->new ({ binary => 1, eol => $/ , sep_char => "\t", always_quote =>1}); print $FILE4 "".<$FILE1>; <$FILE2>; <$FILE3>; my %file2; while (my $row = $csv->getline($FILE2)) { my @fields = @$row; my $id = $fields[0]; $file2{$id}=["",@fields]; } my %file3; while (my $row = $csv->getline($FILE3)) { my @fields = @$row; my $id = $fields[0]; $file3{$id}=["",@fields]; } while (my $row=$csv->getline($FILE1)) { my @fields=@$row; @fields=@fields[map{$_}(0..4)]; my $id=$fields[0]; if (exists $file2{$id}) { if(exists $file3{$id}) { my $fields_ref=\@fields; $csv->print ($FILE4,$fields_ref); } else { } } else { } }

In reply to Deleting a columnheader by bluray

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.