mika6891 has asked for the wisdom of the Perl Monks concerning the following question:
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"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: remove last column of tab-delimited file
by Lotus1 (Vicar) on Jul 22, 2016 at 19:13 UTC | |
|
Re: remove last column of tab-delimited file
by kroach (Pilgrim) on Jul 22, 2016 at 17:57 UTC | |
by mika6891 (Initiate) on Jul 22, 2016 at 18:08 UTC | |
by perldigious (Priest) on Jul 22, 2016 at 18:45 UTC | |
by flowdy (Scribe) on Jul 22, 2016 at 18:46 UTC |