1

Here is the code

 open IN, '</root/Desktop/out.txt' or die "Cannot open file : $!";
 while (<IN>) {
 chomp $_;
 $seq_no= $_;
 my @this_seq=();
 if($seq_no=~ m/^complement\(/){
 push(@this_seq,1);
 $seq_no=~ s/complement\(//g;
 if($seq_no=~ m/^order/){
 push(@this_seq,2);
 $seq_no=~ s/order//g;
 $seq_no=~ s/\(//g;
 $seq_no=~ s/\)//g;
 #my @temp = split(/,/, $seq_no);
 push @this_seq,$seq_no;
 print "@this_seq    \n";
}

}
else
{
 $seq_no=~ s/\(//g;
 $seq_no=~ s/\)//g;
 push @this_seq,$seq_no;
#print "@this_seq \n";
 }
 push @sequence,\@this_seq;
 }
 print @sequence;

The out file is

complement(order(1843..1881,1923..2001,2065..2147, 2216..2277,2330..2468))  
773..1447

But when i print @sequence it just get

ARRAY(0x119adb8)ARRAY(0x117e6b0)

I have already add \@this_seq when push into array, but it still shows memory address, can anyone tell me how to change it to shows array content.

1
  • Use while( my $seq_no = <IN> ){ chomp $seq_no; ... since you don't otherwise use $_. Commented Feb 14, 2014 at 16:47

1 Answer 1

5

When you are doing this:

push @sequence,\@this_seq;

you are pushing a reference to @this_seq into @sequence, so at the end @sequence contains two references to two separate arrays. If that is what you intended then you can print it out like this:

foreach my $seq (@sequence) {
    print join(',', @$seq),"\n";
}

That will print the contents of the two arrays on two separate lines. The outer loop iterates through the array references, the 'join' statement joins together the contents of each of the array refs (note that @$seq de-references the array reference contained in $seq).

Also note that I used join - if you just print an array like this:

print @$seq;

it will print the contents of the array but it won't have commas between each element and there won't be a newline at the end.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.