Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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

by Skeeve (Vicar)
on Jul 31, 2013 at 13:15 UTC ( #1047263=note: print w/replies, xml ) Need Help??


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

Why do you have the strings in arrays and not in hashes?

I'd put the array you search in into a hash where the array elements would be the keys and the value would be the number of occurences.

Finding then the number of occurences for each of your searched keys is simply getting the value from the hash.

foreach my $g (@gl) { print "$g occures ",($hfr_genes{$g} || 0)," time(s)\n"; }

s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

Replies are listed 'Best First'.
Re^2: A better way to make the script run faster?
by Anonymous Monk on Jul 31, 2013 at 13:59 UTC
    Thank you! I sorry but my knowledge with perl is basic as im just a beginner. Hashes did the job really well. But the $hfr_genes{$g} in the print statement prints the -1 location of the occurrence of the values. Is there a way where i can record the number of occurrences? Thanks again!
      See tobyink's answer below.

      s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
      +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1047263]
help
Chatterbox?
[Corion]: choroba: Yeah - I found that if you have the "right" datastructure from the start, it's fairly easy, but if you have some global datastructure that you mutate, you have to rewrite a lot to pass around the results instead.
[Corion]: I find the process quite similar to (in Prolog) passing around an accumulator variable in recursive predicates
[1nickt]: Good morning, brainy monks!
[marto]: Hi 1nickt, I know it's early days, but how is the new job?
[Corion]: Hi 1nickt!
[Corion]: Ohai marto!
[marto]: hey Corion

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2017-12-11 11:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (289 votes). Check out past polls.

    Notices?