Perl find min value with custom compare funciton?

You can create one using reduce from List::Util use List::Util qw/reduce/; $min = reduce { $a.

You can create one using reduce from List::Util. Use List::Util qw/reduce/; $min = reduce { $a.

– wk. Apr 9 at 16:43 @wk: The OP asks for a way to customize the comparison function. – Tim N Apr 9 at 20:50.

But fear not, you can simulate it in perl, or choose the easy solution: my $min = shift @yourlist; # or $yourlist0 if the list must remain intact # assuming that your compare function is named "lower" map { $min = $_ if lower($_, min) } @yourlist.

1 Perl is a functional language. Not a pure one, of course, but it has most of the defining features. – daxim Apr 9 at 9:21 Why would you use a map instead of a for loop?

– Tim N Apr 9 at 9:27 @daxim - I know, thought, syntactic issues and performance make it almost impossible to use it as such. The biggest obstacle, of course, is it's lack of a sound type system - although this is no requirement for functional languages, it certainly makes functional programming really rock. Don't take this as anti Perl advocacy - I am myself an old perl hacker, yet one who sees that sometimes there are better ways to do certain things.

– Ingo Apr 9 at 9:27 @Tim: There's more than 1 way to do it, you know :) - in this particular case, it looked to me as though a next to functional solution was natural. Or perhaps I have done too much Haskell lately, so that imperative constructs like loops don't come to my mind. – Ingo Apr 9 at 9:30 @Ingo: Of course a map works just as well, but I see no reason that a higher-order function would be needed or even make things simpler in this situation.

The use of map seemed to share origin with your desire to use Haskell instead. – Tim N Apr 9 at 9:33.

If you want to compare strings, for example, replace < with le (although List::Util also exports minstr).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions