Brian McCauley wrote: > > First contribution is a module to provide the apply BLOCK LIST > function as decribed in a thread in comp.lang.perl.misc some time > back: > > apply BLOCK LIST > > Similar to map in that it evaluates BLOCK setting $_ to each > element of LIST in turn. apply returns a list made up of the > values of $_ after BLOCK has been evaluated. In a scalar context > the last element is returned. Unlike map and grep the elements > of LIST are not altered. > > @foo = apply { s/\s+/ /g } @bar; # canonicalise whitespace > > This function is nothing more than syntactic sugar for people who find > the following syntax unpalatable. > > for (@foo = @bar) { s/\s+/ /g } > Please excuse my stupid question :-)
What's the difference to the map function. What you've written above, would I have written as @foo = map { s/\s+/ /g } @bar; Greetings, Andrea