in reply to Comparing array of aligned sequences

Not being a bio guy, I don't understand your transfer function. However, when I run your code I get several Use of uninitialized value in string. Using Tip #4 from the Basic debugging checklist (Data::Dumper), I see some undef values in your array. Try to eliminate those first.
use Data::Dumper; print Dumper(\@arr)

Arrays in Perl start with index=0 by default, but you start filling the array at index=1. Maybe you want $seqcount++; at the end of your while loop?

If you just want your input file in an array-of-arrays (perldoc perdsc), this is simpler:

my @arr; open (B, "temp.dat"); while (my $line=<B>) { chomp $line; $line =~ s/\s//g; my @temp = split //, $line; push @arr, [@temp]; }

Replies are listed 'Best First'.
Re^2: Comparing array of aligned sequences
by newtoperlprog (Sexton) on Jul 11, 2014 at 17:05 UTC

    Thank you for your time and reply. I did some modifcations and now the program is printing 3 times each value on match. I guess I am not putting the print at the right place.

    #!/usr/bin/perl use warnings; use strict; use Data::Dumper; my $seqcount; my $pos; my $arrlen; my @arr = (); open (B, "temp.dat"); while (my $line=<B>) { chomp $line; $seqcount++; $line =~ s/\s//g; my @temp = split (//, $line); $arrlen = scalar(@temp); for ($pos=0;$pos<=$#temp;$pos++) { $arr[$seqcount][$pos] = $temp[$pos]; # print "$pos\t$arr[$seqcount][$pos]\n"; } } my $max_position = 0; $max_position = $arrlen if($arrlen > $max_position); for ($pos=0;$pos<=$max_position;$pos++) { for (my $s=1;$s<=$seqcount;$s++) { # print "$pos\t$s\t$arr[$s][$pos]\n"; if ($arr[$s][$pos] ne $arr[$seqcount][$pos]) { print "\n"; next; } else { print "$arr[$s][$pos]"; } } print "\n"; }
    Do I need to push in another array after there is a match of values? Thanks for your help.