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


In reply to Re: cut columns with an array slice by johngg
in thread cut columns with an array slice by coldy

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.