SPUG:Rookie Question

SPUG-list-owner tim at consultix-inc.com
Thu Jul 3 12:38:54 CDT 2003


On Mon, Jun 16, 2003 at 06:58:14PM -0700, ced at carios2.ca.boeing.com wrote:
> > That's not a void context... grep() returns the array which is the
> > object of map(). The return value of map() is used as the key for an
> > anonymous hash, which is then subtracted from $uniq. What is means to
> > subtract a hash from a scalar is a mystery beyond the ken of mere
> > programmers.

What it means, to those of us who know Chuck as I do, is that *he
still can't type*! He's had the benefit of some valuable training
on the Perl language (I know, I was on the other side of the
podium 8-} ), but what he *really needs* is a crash course in
QWERTY interfacing strategies from the Evelyn Woods Institute of
Secretarial Technology. And there's no shame in that, Chuck, so
please ask your boss to schedule you for that training ASAP! 8-]

>  "Hm, Tim doesn't like grep... Maybe  just if used in void 
>   context..." 
> 
> I was suggesting though that this might explain the perceived bias 
> that was ascribed to Tim. 
> 
> Near violence can erupt in some quarters if map or grep or 
> backticked commands are used in void context.
> 
> Quick, Tim, straighten this mess out :) 
> --
> Charles DeRykus 

Sorry, I was at YAPC in Florida straightening out other things when this 
thread appeared, and only just noticed it today. 8-}

I'd like to make it clear that I have *nothing* against grep,
although I'm generally against "scoundreling", which occurs in void
context applications, as Charles et al rightly inferred.

What's scoundreling?  In the words of the Perl Manual from now classic
versions (up to 5.6.1):

  What's wrong with using grep or map in a void context?

   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!

I can't see the code that Chuck was working with at the moment,
but it could probably be converted into just a map{} with a
matching operator inside, instead of a map + grep {} sequence,
and of course that change would save some "list slinging". But
it's probably simpler to code and understand in the map+grep
format, and easier for maintenance programmers to read that way
too, so I wouldn't vote for rewriting it just to cater to the
needs of the CPU over those of the humans! 8-}

-Tim
*------------------------------------------------------------*
| Tim Maher (206) 781-UNIX  (866) DOC-PERL  (866) DOC-UNIX   |
| CEO, JAWCAR ("Just Another White Camel Award Recipient")   |
| tim(AT)Consultix-Inc.Com  TeachMeUnix.Com  TeachMePerl.Com |
*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-*
|  Watch for my Book: "Minimal Perl for Shell Programmers"   |
*------------------------------------------------------------*



More information about the spug-list mailing list