Bob Showalter wrote:
> > -----Original Message----- > > From: drieux [mailto:[EMAIL PROTECTED]] > > Sent: Monday, May 20, 2002 3:01 PM > > To: cgi cgi-list > > Subject: Re: Counting the elements of an array > > > > > > > > On Monday, May 20, 2002, at 08:13 , Bob Showalter wrote: > > >> -----Original Message----- > > >> From: drieux [mailto:[EMAIL PROTECTED]] > > >> > > >> #------------------------ > > >> # > > >> sub haveMap { > > >> my (@list) = @_; > > >> my %seen = (); > > >> > > >> map {$seen{$_}++} @list; > > > > > > So, is the old saw about "don't use map() in a void context" out > > > the window? > > > > you will have to explain this 'old saw' to 'this old dog' > > as this is the first time I have heard it.... > > perldoc -q 'What's wrong with using grep or map in a void context?' says: > > Both grep and map build a return list, regardless of their context. > This means you're making Perl go to the trouble of building up a > return list that you then just ignore. That's no way to treat a > programming language, you insensitive scoundrel! > > perldoc perlstyle says: > > o Avoid using grep() (or map()) or `backticks` in a void > context, that is, when you just throw away their > return values. Those functions all have return > values, so use them. Otherwise use a foreach() loop > or the system() function instead. This is what I was getting at in my previous post, although I guess I wasn't clear enough. When I said it was contentious I didn't mean that drieux was being contentious, just that some people think that using map for side effects is a perfectly reasonable thing to do, and that the only thing wrong with it is that perl doesn't recognize that it is being used in a void context, and therefore goes ahead and builds an unnecesary return list. Other people think it just shouldn't be done as a matter of style. A little googling turned up: http:[EMAIL PROTECTED]/msg00035.html One thing about this post that I disagree with is the idea that people will find it unclear only because of a background in C. I think people may also find it unclear because of a background in functional languages (whence map comes). I like map to be free of side effects even when used in a non-void context (particularly then actually- at least when you use it in a void context it's clear that you must be doing it for the side effects). But Perl has a tradition of more than one way to do it, so to each their own :). (And if I find something that's much more convenient to do this way, I might even try it out :) ). Tagore Smith -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]