develooper Front page | perl.perl5.porters | Postings from December 2007

grep and smart match should warn in void context

Thread Next
Michael G Schwern
December 23, 2007 03:14
grep and smart match should warn in void context
Message ID:
I posted up Alberto's smart match vs grep benchmarks on use.perl.

A few people noted that I was running the checks in void context, maybe
they've been optimized away.  Turns out the context doesn't matter, but that
raised a question... why wasn't I warned about it?

Unlike map, yet like sort, the whole point of grep is the return value.  If
you're not looking at the return value of grep, you've probably made a
mistake.  It should warn in void context as sort does.

Similar thinking about smart match.  There's no good reason to use a
comparison operator in void context.  Come to think of it, grep is really a
comparison operator, too.

I was looking at how to implement this based on sort's warning but it looks
like it requires some op.c voodoo to make it happen efficiently at compile time.

...they shared one last kiss that left a bitter yet sweet taste in her
mouth--kind of like throwing up after eating a junior mint.
    -- Dishonorable Mention, 2005 Bulwer-Lytton Fiction Contest
           by Tami Farmer

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About