perl sub

时间:2024-04-08 11:04:31
#/usr/bin/perl -w

use strict;

my $usage = "\n\nusage: $0 <length>\n\n";

my $length = $ARGV[0] || die $usage;

&RandomSeq($ARGV[0]); # invoke the subroutine

sub RandomSeq {

  for (my $i = 0; $i < $length; $i++) {

    unless ($i%70) {print "\n"};

    my $base = int(rand(4));

    if ($base == 0) {print "A"; next;}

    if ($base == 1) {print "C"; next;}

    if ($base == 2) {print "T"; next;}

    if ($base == 3) {print "G"; next;}

}

print "\n";

}