in reply to cut columns with an array slice

Use splice in a loop working with your columns to remove sorted in descending numerical order. In other words, by working in from the right of the array you don't mess up the indexing for subsequent operations. Note that I assume we are counting from column zero.

knoppix@Microknoppix:/etc$ perl -E ' > open my $colsFH, q{<}, \ <<EOD or die qq{open: << HEREDOC: $!\n}; > 3 > 7 > 4 > EOD > > chomp( my @columns = <$colsFH> ); > close $colsFH or die qq{close: << HEREDOC: $!\n}; > > open my $dataFH, q{<}, \ <<EOD or die qq{open: << HEREDOC: $!\n}; > l1c0 l1c1 l1c2 l1c3 l1c4 l1c5 l1c6 l1c7 l1c8 l1c9 > l2c0 l2c1 l2c2 l2c3 l2c4 l2c5 l2c6 l2c7 l2c8 l2c9 > l3c0 l3c1 l3c2 l3c3 l3c4 l3c5 l3c6 l3c7 l3c8 l3c9 > EOD > > @columns = sort { $b <=> $a } @columns; > > while ( <$dataFH> ) > { > my @dataColumns = split; > splice @dataColumns, $_, 1 for @columns; > say join q{ }, @dataColumns; > } > > close $dataFH or die qq{close: << HEREDOC: $!\n};' l1c0 l1c1 l1c2 l1c5 l1c6 l1c8 l1c9 l2c0 l2c1 l2c2 l2c5 l2c6 l2c8 l2c9 l3c0 l3c1 l3c2 l3c5 l3c6 l3c8 l3c9 knoppix@Microknoppix:/etc$

I hope this is helpful.

Cheers,

JohnGG