Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: A better way to make the script run faster?

by tobyink (Abbot)
on Jul 31, 2013 at 13:22 UTC ( #1047265=note: print w/ replies, xml ) Need Help??


in reply to A better way to make the script run faster?

Use a frickin hash!

use strict; use warnings; my @gl = qw( CD9 TBN NANOG KITL FUT4 SALL4 MYC STAT3 ESRRB AKP2 SOX2 POU5F1 KLF4 ); my @hfr_genes = qw( LYPLA1 LYPLA1 LYPLA1 LYPLA1 STAT3 LYPLA1 LYPLA1 STAT3 LYPLA1 LYPLA1 LYPLA1 LYPLA1 SOX2 ); # First thing: convert @hfr_genes into a hash!!! # Looking up a hash key is much faster than grepping an array. my %hfr_genes; $hfr_genes{$_}++ for @hfr_genes; # Now loop through the first list for (@gl) { my $count = $hfr_genes{$_}; print "Value $_ is present $count times\n" if $count; }
package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name


Comment on Re: A better way to make the script run faster?
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2014-09-02 05:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (20 votes), past polls