Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7546159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:07:42+00:00 2026-05-30T09:07:42+00:00

My code: use strict; use warnings; my $seq = ATGGT[TGA]G[TA]GC; print The sequences is

  • 0

My code:

use strict;  
use warnings;

my $seq = "ATGGT[TGA]G[TA]GC";  
print "The sequences is $seq\n";  
my %regex = (  
   AG => "R",  
   TC => "Y",  
   GT => "K",  
   AC => "M",  
   GC => "S",  
   AT => "M",  
   CGT => "B",  
   TGA => "D",  
   ACT => "H",  
   ACG => "V",  
   ACGT => "N"  
);  

$seq =~ s/\[(\w+)\]/$regex{$1}/g;  
print "$seq\n";  

My ideal output is: ATGGTDGMGC
But in the above scenario, since my hash key is AT and not TA, it doesn’t run. One way to solve this problem would be adding another key-value: TA => “M”. But I cannot do this for all key-value pairs, as there are too many possibilities.

So is there a better way to address this issue??

Thanks..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T09:07:43+00:00Added an answer on May 30, 2026 at 9:07 am

    I’m guessing you mean that the order of the stuff in brackets is unimportant, so AT is equivalent to TA, and TAG equivalent to TGA, etc.

    [ Note that the other Eric made a different guess. You weren’t very clear on what you wanted. ]

    You could sort the letters.

    sub key { join '', sort split //, $_[0] }
    
    my @subs = (
       AG => "R",
       TC => "Y",
       GT => "K",
       AC => "M",
       GC => "S",
       AT => "M",
       CGT => "B",
       TGA => "D",
       ACT => "H",
       ACG => "V",
       ACGT => "N",
    );  
    
    my %subs;
    while (@subs) {
        my $key = shift(@subs);
        my $val = shift(@subs);
        $subs{ key($key) } = $val;
    }
    
    # Die on unrecognized
    $seq =~ s/\[(\w+)\]/ $subs{ key($1) } or die $1 /ge;
    

    or

    # Do nothing on unrecognized
    $seq =~ s/\[(\w+)\]/ $subs{ key($1) } || $1 /ge;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code triggers the complaint below: #!/usr/bin/perl use strict; use warnings; my $s =
Here's the code I have: use strict; use warnings; use Log::Log4perl qw(:easy); Log::Log4perl->init({ level
Consider the following Perl code. #!/usr/bin/perl use strict; use warnings; $b=1; my $a=${b}; $b=2;
This is the perl code ... use strict; use warnings; use LWP::UserAgent; use HTTP::Date;
the following code #!/usr/bin/env perl use strict; use warnings; my @foo = (0,1,2,3,4); foreach
use strict; use warnings; open(FILE1,/cygdrive/c/cpros/karthik/molk.txt); my $line = < FILE1 > ; print $line
Running the following code : use strict; use warnings; use Benchmark; my $defaultArray =
I have this code use strict; use warnings; my %hash; $hash{'1'}= {'Make' => 'Toyota','Color'
I have this code which works. #!/usr/bin/perl use warnings; use strict; use Net::LDAP; use
I have code that contains: use strict; use warnings; use List::Util; my $index =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.