I'm loading and printing tab-delimited files in my perl script. However the last column of my input file ($table1) is empty and I don't want to print this in my output file ($table3). How and where should I do this? After the 'open' or at the end in the 'print $table3'? This is part of my script (... denotes code not important for this question)

#! /usr/bin/perl use strict; use warnings; use Data::Dumper; local $Data::Dumper::Useqq = 1; use Getopt::Long qw(GetOptions);; ... open(my $table1,'<', $input) or die "$! - [$input]"; #input file open(my $table3, '+>', $output) || die ("Can't write new file: $!"); # +output file ... chomp( my @header_for_table1 = split /\t/, <$table1> ); print $table3 join "\t", @header_for_table1, "name1", "name2", "\n"; { no warnings 'uninitialized'; while(<$table1>){ chomp; my %row; @row{@header_for_table1} = split /\t/; print $table3 join ( "\t", @row{@header_for_table1}, @{ $lookup{ ... } // [ "", "" ] }), "\n"; } }

In reply to remove last column of tab-delimited file by mika6891

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.