Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: char substitution without regexes

by ikegami (Patriarch)
on Sep 30, 2010 at 17:12 UTC ( [id://862814]=note: print w/replies, xml ) Need Help??


in reply to char substitution without regexes

Awww, jwkrahn beat me to it. Here's one that doesn't use tr/// either:
my %complement = ( a t g c ); %complement = ( %complement, reverse %complement ); print map $complement{$_}, reverse split //, $chain;

%hash and $string are awful names, so I changed them.

Replies are listed 'Best First'.
Re^2: char substitution without regexes
by jwkrahn (Abbot) on Sep 30, 2010 at 17:59 UTC

    Yes, but, that uses a regex and the OP said "without regexes".

      It passes a pattern, but it's actually special-cased not to use the regex engine.

      Ok, so I did it without thinking.

      print map $complement{$_}, reverse unpack '(a)*', $chain;

        Now you've got it!   :-)

        By the way, which do you think would be more efficient, reversing the list, or reversing the string first?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2026-04-22 14:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.