Path: utzoo!utgpu!cunews!cognos!alanm From: alanm@cognos.UUCP (Alan Myrvold) Newsgroups: comp.lang.perl Subject: Re: Arithmetic functions Message-ID: <9380@cognos.UUCP> Date: 27 Feb 91 19:13:33 GMT References: <1991Feb20.113935.14427@pronto.mh.nl> <1991Feb26.080757.21645@pronto.mh.nl> Reply-To: alanm@cognos.UUCP (Alan Myrvold) Distribution: comp Organization: Cognos Inc., Ottawa, Canada Lines: 18 In article <1991Feb26.080757.21645@pronto.mh.nl> Johan Vromans writes: >I don't even think of using sort to get the max or min of two numbers. So what would be the preferred way of getting the min or max of a list of numbers, short of adding it to Perl? How about : sub min { local ($v) = (shift @_); grep(($_ < $v) && ($v = $_),@_); $v; } sub max { local ($v) = (shift @_); grep(($_ > $v) && ($v = $_),@_); $v; } - Alan --- Alan Myrvold 3755 Riverside Dr. uunet!mitel!cunews!cognos!alanm Cognos Incorporated P.O. Box 9707 alanm%cognos.uucp@ccs.carleton.ca (613) 738-1440 x5530 Ottawa, Ontario CANADA K1G 3Z4