Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: char substitution without regexes

by Anonymous Monk
on Oct 01, 2010 at 12:42 UTC ( [id://862963]=note: print w/replies, xml ) Need Help??


in reply to char substitution without regexes

for (my $i = length($string); $i>= 0 ; $i--){ print $hash{ substr($string, $i, 1) }; }

Replies are listed 'Best First'.
Re^2: char substitution without regexes
by Soul Singin' (Initiate) on Oct 02, 2010 at 16:12 UTC

    Here's a variant on the above, but syntactically clearer:

    #!/usr/bin/env perl use strict ; use warnings ; ## DNA string my $string = "aaaggctt"; ## syntactically clear hash my %hash = ( "a" => "t" , "g" => "c" , "c" => "g" , "t" => "a" ); ## print the DNA string and reverse complement ## add some extra spacing to make it look pretty print "\n" ; print "\t The DNA string is: " . $string . "\n" ; print "\tThe reverse complement is: " ; ## go through the string one element at a time ## and print reverse complement for my $i (0..length($string)-1) { print $hash{ substr($string, $i, 1) } ; } ## finish with a little extra spacing print "\n\n" ;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2026-04-22 20:31 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.