in reply to match search string with column header, do some filtering with matched column, print lines/rows that match filter criteria

While I do not know the answer to your current question, I do think your code is irreparably broken as long as you insist on using eval like that. BrowserUK gave a very good suggestion here to invoke the operators using a dispatch table (a hash of function references, each taking two arguments). You should incorporate that into your code.

  • Comment on Re: match search string with column header, do some filtering with matched column, print lines/rows that match filter criteria

Replies are listed 'Best First'.
Re^2: match search string with column header, do some filtering with matched column, print lines/rows that match filter criteria
by Anonymous Monk on Jul 27, 2012 at 12:08 UTC

    Anyway, eval is so very rarely needed and should be shunned. But you wanted minor corrections. Let's see...

    Change

    if ((eval "$cells[$extract_col] $filter_array[$i][1] $filter_array[$i] +[2]"))
    to
    if ((eval '$cells[$extract_col] ' . $filter_array[$i][1] . ' $filter_a +rray[$i][2]'))

    I need to print the entire row of the input file to the output file

    Then why don't you do so? Change

    print OUTFILE "$cells[$extract_col]", "\n";

    to

    print OUTFILE $row, "\n";

    The clarity of your code would be somewhat enhanced if you gave @filter_array's columns names; e.g. $filter_array[$i]->{action} = 'append' or $filter_array[$i]->{column} = 'c'. Remember: with clear code, it is easier to be certain that it works correct.

    Oh, and please stop quoting "$var" since it is identical to plain $var -- barring a few exceptions having to do with references and objects.