Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Increasing the efficiency of the code

by Fengor (Pilgrim)
on Nov 29, 2006 at 13:04 UTC ( #586680=note: print w/ replies, xml ) Need Help??


in reply to Increasing the efficiency of the code

I don't know if it would actually increase performance but since the whole thing seems to be about wrapping from numerical to string context that gave me an idea. If you implemented a hash with the numerical operators as keys and the string operators as their corresponding values couldn't you rewrite the whole if elsif else etc construct as:

if (eval "$conwithposition{$key_pos}[1] $mapContext{$conwithposition{$ +key_pos}[0] $line[$key_pos]"){ foreach $col(sort {$a<=>$b} keys(%cols_pos)){ push @tmparr,$line[$col]; } $tmparr=join("|",@tmparr); push @listcols,$cols_pos{$col}; push @result_arr,[ $tmparr ];

--
"WHAT CAN THE HARVEST HOPE FOR IF NOT THE CARE OF THE REAPER MAN"
-- Terry Pratchett, "Reaper Man"


Comment on Re: Increasing the efficiency of the code
Download Code
Re^2: Increasing the efficiency of the code
by Limbic~Region (Chancellor) on Nov 29, 2006 at 13:14 UTC
    Fengor,
    If you implemented a hash with the numerical operators as keys and the string operators as their corresponding values couldn't you rewrite the whole if elsif else etc construct as:

    You have a good idea and yes, it will lead to a performance increase. Unfortunately your implementation is less than desireable. Using a string eval can be very dangerous and should be avoided when better alternatives exist. In this case, a dispatch table is better suited. See my post below for an example.

    Cheers - L~R

      hmm thx, at least tis good to know i wasnt totally on the wrong track. That dispatch table looks good guess its about time to add that trick to my book ;)

      --
      "WHAT CAN THE HARVEST HOPE FOR IF NOT THE CARE OF THE REAPER MAN"
      -- Terry Pratchett, "Reaper Man"

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2014-08-31 04:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls