I have a high amount of 'strings' to tr. If I input:
my $index = 0200104;
It would have to change every 'string' at pos1 tr/02/20/, then at pos4 tr/01/10/, then at pos6 tr/04/40/. And there is quite an amount of 'indexes'. I thought there could be something faster ?
Thanks | [reply] [d/l] |
What is the bigger picture? It may be that there is a better way of achieving the overall goal than using the technique you are trying to micro-optimize in this thread.
Have you even done any timing to suggest that the speed of the problem being solved by this code is actually an issue?
DWIM is Perl's answer to Gödel
| [reply] |
No matter how many lines it takes to write, if you've got to perform an operation on every element, it's (at least) an O(n) process. Give us some more information about the actual data you're converting. Is this something like a big-endian => little-endian conversion? Are the strings of a consistent length? Is it numeric data? In the case you show, it appears you want to change 0200104 to 220000 (tr/// would change the 0 in position 1 to a 2, the 1 in position 4 to a 0, and the 4 in position 6 to a 0). Is this correct?
emc
Information about American English usage here and here.
Any New York City or Connecticut area jobs? I'm currently unemployed.
| [reply] |