in reply to Re: remove last column of tab-delimited file
in thread remove last column of tab-delimited file

Would something like this work then?
chomp( my @header_for_table1 = split /\t/, <$table1> ); @new_header_for_table1 = pop(@header_for_table1); print $table3 join "\t", @new_header_for_table1, "name1", "name2", "\n +";

Replies are listed 'Best First'.
Re^3: remove last column of tab-delimited file
by perldigious (Priest) on Jul 22, 2016 at 18:45 UTC

    No need to assign the pop operation to anything since you want to throw it away. Just:

    pop(@header_for_table1);

    EDIT:

    To clarify, pop will alter the array you are using it on by removing the last element. It returns the last element that is removed, not all the remaining elements excluding the last element removed. So the code you showed would create a new array with just one element, the last element of the original array you wanted to discard. That's not what you want.

    I love it when things get difficult; after all, difficult pays the mortgage. - Dr. Keith Whites
    I hate it when things get difficult, so I'll just sell my house and rent cheap instead. - perldigious
Re^3: remove last column of tab-delimited file
by flowdy (Scribe) on Jul 22, 2016 at 18:46 UTC

    Why don't you try it instead of asking? ;)

    I would use splice @header_for_table1, -1 without assignment, as splice returns what it has removed from an array. Likewise pop cuts the last element off an array and returns it, but in contrary what you want is all items but the last, don't you?

    UPDATE: pop() without assignment is the same like splice(@array, -1), yeah.