Új hozzászólás Aktív témák

  • Zola007

    veterán

    Ezt meg lehet rövidebben vagy kevesebb változóval oldani (Perl 5.24)?

    #!/usr/bin/perl -w
    # Write a program that switches two bases in a DNA string at specified positions.

    # Get the name of the file with the DNA sequence data
    print "Please type in the sequence need to be modified: ";
    $DNA = <STDIN>;
    # Remove the newline
    chomp $DNA;
    # Get the base would like to change
    print "Please type in which positions would like to switch?\n";
    print " This position: ";
    $pos1 = <STDIN>;
    print "\n to this one: ";
    $pos2 = <STDIN>;
    # Remove the newline
    chomp $pos1;
    chomp $pos2;
    # detect the bases at given positions to be modified
    $base1= substr $DNA,($pos1 - 1),1;
    $base2= substr $DNA,($pos2 - 1),1;
    # change the bases among each other
    $swap = substr $DNA,($pos1 - 1),1,$base2;
    $swap = substr $DNA,($pos2 - 1),1,$base1;
    print "The modified sequence is ",$DNA;
    exit;

Új hozzászólás Aktív témák

Hirdetés