home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!nestroy.wu-wien.ac.at!dec4.wu-wien.ac.at!neumann
- From: neumann@dec4.wu-wien.ac.at (Gustaf Neumann)
- Newsgroups: comp.lang.perl
- Subject: Re: In 5.0, are we gonna get...
- Date: Fri, 18 Dec 92 20:10:07 MET
- Organization: WU-Wien
- Lines: 38
- Distribution: world
- Message-ID: <7247058078-316993@dec4.wu-wien.ac.at>
- 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>
- NNTP-Posting-Host: dec4.wu-wien.ac.at
-
- In article <1992Dec18.140112.18192@cs.ruu.nl> from [Fri, 18 Dec 1992 14:01:12 GMT] you wrote:
- |>
- |> I would like to write:
- |>
- |> $max = reduce { $a > $b ? $a : $b } @row
- |>
- |> -- Another idea would be to have a reduce in array-context,
- |> for example to squeeze out adjacent equal elements:
- |>
- |> @uniq = reduce { ($a eq $b) ? ($a) : ($a,$b) } @row
- |>
- |> Here the ab-sub is evaluated in array-context. The first time
- |> $a is the first element of @row, later on the last element
- |> of the partial result.
-
- this examples are still pretty trivial in current perl:
-
- sub reduce {
- local($f,@array) = @_;
- local($a) = shift @array;
-
- return $a unless @array;
- local($b) = &red($f,@array);
- return eval $f;
- }
-
- print &reduce('$a > $b ? $a : $b',1,6,5,8,3,4),"\n";
- print &reduce('$a < $b ? $a : $b',1,6,5,8,3,4),"\n";
- print &reduce('$a + $b',1,6,5,8,3,4),"\n";
-
- your array examples are more tricky.
- -gustaf
- --
- Gustaf Neumann neumann@dec4.wu-wien.ac.at, neumann@awiwuw11.bitnet
- Vienna University of Economics and Business Administration
- Augasse 2-6, A-1090 Vienna, Austria
- Tel: +43 (222) 31-336 x4533 Fax: 347-555
-
-