coolda has asked for the wisdom of the Perl Monks concerning the following question:
Hello, I'm having a problem trying to add arrays to an array. My purpose is to see if each files have the same first columns, and output a file that doesn't have the same columns. All the files follow the same table format(tab delimited). So from each file, i took out the first column and stored it to an array(@row1). And i stored those arrays of first column in to another array @row. However, when i run it, @row doesn't contain array but number of columns. when i print $row [0] , $row[ 2) or etc, it will print numbers not the array of columns i intended to store. can someone tell me how i can fix this problem?
#!/usr/bin/perl -w use strict; use warnings; use File::Basename; die "Usage: perl extracting.pl [directory where files are located] \n +" unless ($#ARGV ==0); my ($folderin) = @ARGV ; #$dirname = "/data/lgsg/yuho/ProjectSuccess.extracting2columns/sort/ge +neReadCount" opendir(DIR, "$folderin") || die "cannot openfolder"; my @list = readdir (DIR); closedir(DIR); for(1..2){shift @list;} my ($filecount, $rowcount) = 0 ; my (@filename, @row); foreach my $fileone (@list) { $filename[$filecount] = $fileone; open(RES,"$folderin/$fileone") || die "could nottt open $fileone\n +"; <RES>; <RES>; my $count = 0; my $row1; my @genes; while(<RES>){ $row1[$count] =(split /\t/)[0]; $count++; } $row[$filecount] = @row1; $filecount++; } my $unmatched = 0 ; my @names; my $filecount1 =$filecount-1; for (my$chr =1; $chr <= $filecount1; $chr++){ if ($row[0] ne $row[$chr]) { $names[$unmatched] =$filename[$chr]; $unmatched++; } } print "Total # of files compared: $filecount \n"; print "Total # of files unmatched: $unmatched\n"; print "name of the files unmatched : @names \n " ;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: adding arrays to an array
by LanX (Saint) on Oct 23, 2014 at 21:48 UTC | |
by coolda (Novice) on Oct 24, 2014 at 14:03 UTC | |
by LanX (Saint) on Oct 24, 2014 at 15:28 UTC | |
by coolda (Novice) on Oct 24, 2014 at 16:12 UTC |