Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks
I have a dataset with columns and I want to evaluate a statement on each of the rows in the data. I can do this pretty easily. Loop
through each column, check if the column exists in the evaluation statement. If it does, replace the column name with the value
and do the evaluation. I can easily do this using regular expressions. Just curious how a true perl monk would approach this.
#!/usr/bin/perl use strict; use warnings; my $row = { a => 1, b => 2, c => 3, d => 4 }; my $evalStatement="a>0"; sub evaluateRow { my ($row) = @_; ## loop through each column a,b,c,d and if column exists in the evalua +tion statement ## replace column with value if (eval(1>0)) { return 1 ## "ACCEPT row" } return 0 ## "REMOVE row" }
Thank you !!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: column replacement evaluation on dataset
by choroba (Cardinal) on May 24, 2023 at 15:37 UTC | |
|
Re: column replacement evaluation on dataset
by tybalt89 (Monsignor) on May 24, 2023 at 23:13 UTC | |
|
Re: column replacement evaluation on dataset
by Anonymous Monk on May 24, 2023 at 15:33 UTC |