Perl引用

##########################字符串引用##########################

$value="ATGCN";
print $value,"\n";
$valueRef=\$value; #引用
print "$value and $valueRef\n";
$derefRalueRef=${$valueRef}; 
print "$value and $valueRef and $derefRalueRef\n";

##########################匿名字符串引用#######################

$value1=\ "ATGCNGG";
print ${$value1},"\n";

##########################数组引用#############################

@sequences=("ATTTAC","AACCGCTT","AACCTT"); 
print @sequences,"\n";
print "@sequences","\n"; 
$arrayRef=\@sequences;
print $arrayRef,"\n";
@deRefarray=@{$arrayRef};
print "@deRefarray","\n";

print "*******************","\n";
print @{$arrayRef}[0],"\n";
print "*******************","\n";


print ref($arrayRef),"\n"; 

print $arrayRef -> [0],"\n";  
print $arrayRef -> [1],"\n";
print $arrayRef -> [2],"\n";
print $arrayRef -> [0]," ",$arrayRef -> [1]," ",$arrayRef -> [2],"\n";

###############################匿名数组引用############################

$sequences = ["ATACGCA","GGCCATA","CAGATATCAAA"];
print $sequences,"\n";
print ref($sequences),"\n";
print $sequences -> [0]," ",$sequences -> [1]," ",$sequences -> [2],"\n";

###############################多维数组的引用############################

$sequences=[["ATCGCGA","GCCAATG","GGAACCTT"],["AAATTTGGCCAGG","AGAGTACAGCAT","AGGC"],["ATTCA","GGCCAA","GGGAAAGGTTAAGGTT"]];
print "@{$sequences}","\n";
print $sequences,"\n";
print ref($sequences),"\n";
print $sequences -> [0],"\n"; 
print $sequences -> [1],"\n";
print $sequences -> [2],"\n";
print $sequences -> [0][0],"\n";

for $i (0..2){
    for $j (0..2){
        print $sequences -> [$i][$j],"\n";
        }
    }
print "########################","\n";
for $i (0..2){
    for $j (0..2){
        print $sequences -> [$i] -> [$j],"\n";
        }
    }
print "#########################","\n";
for $i (0..2){
    print $sequences -> [$i],"\n";
    }

##########################hash引用###########################
use Data::Dumper;
my %dzHash=(
                    "ID123" => "gff",
                    "ID124" => "gff1",
                    "ID125" => "gff3"
          );
print %dzHash."\n"; 
print scalar(%dzHash),"\n";
print %dzHash,"\n";
my $refdzHash=\ %dzHash;
print Dumper($refdzHash);
print ref($refdzHash),"\n";
print %{$refdzHash},"\n";
print $refdzHash,"\n";
print $refdzHash -> {ID123},"\n";
print $refdzHash -> {ID125},"\n";

print %{$refdzHash},"\n";
print %{$refdzHash}{ID124},"\n"; 
for my $K (keys %{$refdzHash}){
    print "keys:",$K,"\t","value:",$refdzHash -> {$K},"\n";
    }


####################匿名hash##########################
$myniHash={
                    "ID123" => "gff",
                    "ID124" => "gff1",
                    "ID125" => "gff3"
                    };
print $myniHash,"\n";
print %{$myniHash},"\n";
print $myniHash -> {ID124},"\n";
for $d (keys %{$myniHash}){
    print "keys:",$d,"\t","value:",$myniHash -> {$d},"\n";
    }

$filename="test.gff3";
open(R,"$filename") || die "Can not open $filename\n";
open(W,">$filename.mRNA");
my %geneInfo=();
my $refgeneInfo=\ %geneInfo;
while (my $file=<R>){
    chomp $file;
    if ($file=~/^#/){
        next;
        }
    my @temp=split("\t",$file);
    if ($temp[2] eq "gene"){ 
        $temp[-1]=~/ID=([^;]+)?/;
        my $geneID=$1; 
        $refgeneInfo -> {$geneID} -> {'location'} = [$temp[0],$temp[3],$temp[4]];
        }
    if ($temp[2] eq "mRNA"){
        $temp[-1]=~/ID=([^;]+).Parent=([^;]+)/;
        push(@{$refgeneInfo->{$2}->{transcripts}},{"start" => $temp[3],"end" => $temp[4],"chr" =>$temp[0],"mRNA" =>$1});
        }
    }

for my $id (keys %{$refgeneInfo}){
    print $refgeneInfo -> {$id} ->{location},"\n";
    print $refgeneInfo -> {$id} -> {transcripts},"\n"; 

    if ( ($refgeneInfo -> {$id} -> {transcripts}) ne ""){
        print  $refgeneInfo -> {$id} -> {transcripts} -> [0] ->{mRNA},"\n";
        }
    print "\n";
    }
close R;
close W;
此条目发表在Perl分类目录。将固定链接加入收藏夹。

发表评论

邮箱地址不会被公开。 必填项已用*标注

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

Protected with IP Blacklist CloudIP Blacklist Cloud