home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / perl / 7555 < prev    next >
Encoding:
Internet Message Format  |  1992-12-21  |  1.7 KB

  1. Path: sparky!uunet!nestroy.wu-wien.ac.at!dec4.wu-wien.ac.at!neumann
  2. From: neumann@dec4.wu-wien.ac.at (Gustaf Neumann)
  3. Newsgroups: comp.lang.perl
  4. Subject: Re: In 5.0, are we gonna get...
  5. Date: Fri, 18 Dec 92 20:10:07 MET
  6. Organization: WU-Wien
  7. Lines: 38
  8. Distribution: world
  9. Message-ID: <7247058078-316993@dec4.wu-wien.ac.at>
  10. References: <1992Dec14.043835.23009@reed.edu> <1992Dec14.192007.7534@wdl.loral.com> <2B2D2498.874E@tct.com> <7246288358-314904@dec4.wu-wien.ac.at> <1992Dec18.140112.18192@cs.ruu.nl>
  11. NNTP-Posting-Host: dec4.wu-wien.ac.at
  12.  
  13. In article <1992Dec18.140112.18192@cs.ruu.nl> from [Fri, 18 Dec 1992 14:01:12 GMT] you wrote:
  14.  |> 
  15.  |>   I would like to write:
  16.  |> 
  17.  |>     $max = reduce { $a >  $b ? $a : $b } @row
  18.  |>   
  19.  |> -- Another idea would be to have a reduce in array-context,
  20.  |>    for example to squeeze out adjacent equal elements:
  21.  |> 
  22.  |>      @uniq = reduce { ($a eq $b) ? ($a) : ($a,$b) } @row
  23.  |>    
  24.  |>    Here the ab-sub is evaluated in array-context. The first time
  25.  |>    $a is the first element of @row, later on the last element
  26.  |>    of the partial result.
  27.  
  28. this examples are still pretty trivial in current perl:
  29.  
  30. sub reduce {
  31.     local($f,@array) = @_;
  32.     local($a) = shift @array;
  33.  
  34.     return $a unless @array;
  35.     local($b) = &red($f,@array);
  36.     return eval $f;
  37. }
  38.  
  39. print &reduce('$a >  $b ? $a : $b',1,6,5,8,3,4),"\n";
  40. print &reduce('$a <  $b ? $a : $b',1,6,5,8,3,4),"\n";
  41. print &reduce('$a + $b',1,6,5,8,3,4),"\n";
  42.  
  43. your array examples are more tricky.
  44. -gustaf
  45. --
  46. Gustaf Neumann          neumann@dec4.wu-wien.ac.at, neumann@awiwuw11.bitnet
  47. Vienna University of Economics and Business Administration 
  48. Augasse 2-6,  A-1090 Vienna, Austria        
  49. Tel: +43 (222) 31-336 x4533      Fax: 347-555
  50.  
  51.