Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Re: Re:x2 Counting keys with defined or undefined elements in a hash

by broquaint (Abbot)
on Jun 05, 2003 at 18:45 UTC ( [id://263452] : note . print w/replies, xml ) Need Help??


in reply to Re: Re:x2 Counting keys with defined or undefined elements in a hash
in thread Counting keys with defined or undefined elements in a hash

Using grep is deceptively fast
Since it performs the iteration internally it is bound to be very fast indeed, and scalar context will also help as it saves on the assignment. Will also do my best not to offend anyone's aesthetic sensibilities in future ;)
HTH

_________
broquaint

  • Comment on Re: Re: Re:x2 Counting keys with defined or undefined elements in a hash

Replies are listed 'Best First'.
Re: Re: Re: Re:x2 Counting keys with defined or undefined elements in a hash
by jsprat (Curate) on Jun 05, 2003 at 19:01 UTC
    The key difference between the two (in this case, at least) is the conditional expression. A plain for loop will iterate faster than grep - but insert a conditional into the for loop, grep will win. Side note, in this thread I learned that grep in scalar context doesn't build the list, it just "returns the number of times the expression was true."*

    * ripped directly from perldoc -f grep

    And by the way, if you saw how my apartment was decorated before I got married, you'd never worry about my aesthetic sensibilities again ;)