>>>>> "RArul" == RArul  <[EMAIL PROTECTED]> writes:

RArul> a) Why do perl gurus exhort, not to use 'grep' or 'map'
RArul> functions under void context?

It is only an artifact of implementation that altering $_ can alter
the input list.  The purpose of map or grep is to process a list to
produce an output result, not to alter an input list.

I abused the "$_ is aliased" feature of grep in the Perl3 days, and I
regret that, because it became a part of the culture through my
prolific postings.

Even in a void context, grep and map build up an output list, so it's
wasting CPU to do that.

At first you could argue that there really wasn't anything as concise
as:

        grep s/foo/bar/, @list;

but now we have

        s/foo/bar/ for @list;

which is even shorter. :)

So for those many reasons, we who have been using Perl for more than
10 years say no to grep/map in void context.

RArul> b) What other functions, are to be avoided in 'void' context?

Well, anything whose primary purpose is to "return" something.  Like
"?:", for example.  I can't think of many others at the moment, sorry.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to