home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!mcsun!sun4nl!ruuinf!henkp
- From: henkp@cs.ruu.nl (Henk Penning)
- Subject: Re: In 5.0, are we gonna get...
- Sender: network-news@cs.ruu.nl
- Message-ID: <1992Dec18.140112.18192@cs.ruu.nl>
- Date: Fri, 18 Dec 1992 14:01:12 GMT
- References: <1992Dec14.043835.23009@reed.edu> <1992Dec14.192007.7534@wdl.loral.com> <2B2D2498.874E@tct.com> <7246288358-314904@dec4.wu-wien.ac.at>
- Organization: Utrecht University, Dept. of Computer Science
- Lines: 44
-
- In <7246288358-314904@dec4.wu-wien.ac.at> neumann@dec4.wu-wien.ac.at (Gustaf Neumann) writes:
-
- > [ ... ] how about
- >
- > $sum = eval join('+ ',1,34,$x,45,-8,0.1);
- >
- >ok, the string conversion could be avoided, but you can do it now...
-
- >Gustaf Neumann neumann@dec4.wu-wien.ac.at, neumann@awiwuw11.bitnet
-
- 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.
-
- -- Computing the difference of adjacent elements diff[i]=row[i+1]-row[i]
-
- @diff = reduce { ($b-$a,$b) } @row ; pop @diff ;
-
- -- Range compression: 1,3,4,5,7,22 -> 1,3..5,7,22
-
- sub compress
- { if ( $a =~ /^(\d+)\.\.(\d+)$/ )
- { ( $b == $2 + 1 ) ? ("$1..$b") : ($a,$b) ; }
- else
- { ( $b == $a + 1 ) ? ("$a..$b") : ($a,$b) ; }
- }
-
- @compress = reduce compress @row ;
-
- -- The examples have not been tested (;-) but the code looks nice.
- The scalar-reduce is much more important to have than the
- array-reduce, but I think there is a case for the latter too.
-
- === HenkP ===
-
-