Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: question for perl book & magazine authors

by runrig (Abbot)
on Oct 19, 2005 at 21:48 UTC ( #501441=note: print w/ replies, xml ) Need Help??


in reply to question for perl book & magazine authors

I'm convinced that map & grep aren't as heavily used as they could be because people don't understand them.
And because (some) people don't understand them, it's also (sometimes) hard for people to use them correctly and tell at a glance what is going on. Take, for instance, your 'using grep' example. It doesn't work (also, you are using 'eq' in one vs. '==' in the other which may make an unfair benchmark). I assume you are finding common elements but eliminating any duplicates from the output. The grep example isn't eliminating items that have already been seen because it's not keeping track of what's been seen. I think you were aiming more for this (though I assume the O(n**2) algorithm is on purpose just for demonstration purposes):
'using grep' => sub { my @common; my %seen; @common = grep { my $element1 = $_; !$seen{$element1}++ and grep { $element1 eq $_ } @array2 } @array1; },
Update: and after the fix, the benchmark doesn't favor grep nearly as much.


Comment on Re: question for perl book & magazine authors
Download Code
Re^2: question for perl book & magazine authors
by jfroebe (Vicar) on Oct 20, 2005 at 03:01 UTC
    dang typos of mine!

    Thanks! :)

    Jason L. Froebe

    Team Sybase member

    No one has seen what you have seen, and until that happens, we're all going to think that you're nuts. - Jack O'Neil, Stargate SG-1

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://501441]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (11)
As of 2014-12-22 12:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (117 votes), past polls