Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: tr at a given pos

by duff (Parson)
on Aug 21, 2007 at 21:22 UTC ( [id://634194]=note: print w/replies, xml ) Need Help??


in reply to tr at a given pos

I may be missing something, but why not just loop over your positions? Why must it all be "in one tr"?

Replies are listed 'Best First'.
Re^2: tr at a given pos
by FFRANK (Beadle) on Aug 21, 2007 at 21:36 UTC
    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

      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

      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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-23 06:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found