Anonymous Monk,
I have re-written your code to be to possibly be much more efficient. I have not provided comments so I suspect you won't immediately understand it. The strict and warnings pragmas can point out a lot of problems in your code and as such should be used.
my @sorted_keys = sort keys %conwithpostion; my @sorted_cols = sort {$a <=> $b} keys %cols_pos; my %dispatch = ( '=' => sub {$_[0] eq $_[1]}, '!=' => sub {$_[0] ne $_[1]}, '>' => sub {$_[0] gt $_[1]}, '>=' => sub {$_[0] ge $_[1]}, '<' => sub {$_[0] lt $_[1]}, '<=' => sub {$_[0] le $_[1]}, ); for (@array) { my $match = 0; my @line = split /\t/; for my $key_pos (@sorted_keys) { my ($op, $arg1, $arg2) = (@{$conwithposition{$key_pos}}[0, 1], + $line[$key_pos]); $match = $dispatch{$op}->($arg1, $arg2); last if ! $match; my $col = $sorted_cols[-1]; push @listcols, $col; push @result_arr, join '|', @line[@sorted_cols]; } }
Please feel free to ask questions, but try to find the answers on your own first. See Coping with Scoping and perldoc (also available from the command line) for starters. The trick I did to avoid the if/eslif chain is called a dispatch table.

Update: As GrandFather points out in his node, your use of $col is likely incorrect. I set $col to the last value of the sorted %cols_pos keys on the assumption you thought that is the value it would be after the loop. If $col is set elsewhere in your code then you will need to change this accordingly.

Cheers - L~R


In reply to Re: Increasing the efficiency of the code by Limbic~Region
in thread Increasing the efficiency of the code by Anonymous Monk

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.