I have a sub named “lookup” which does a lookup in a hash for a given value.
I realized it would be much more powerful if I can ask it to look not for a given value, but a value smaller than the one passed as a parameter.
I could make lookupbigger, lookupsmall.. etc, but I am sure there is a better way.
# lookup id according to the search criteria
sub lookup {
my( $data, $lk, $lv ) = ( @_ );
my @res;
foreach my $key (keys $data) {
my $value = $$data{$key};
next unless( defined $$value{$lk} );
# this is the line where I want to replace eq with another operator
push(@res, $key) if( $$value{$lk} eq $lv );
}
return \@res;
}
You can pass a criterion function to your lookup function: