fasoli has asked for the wisdom of the Perl Monks concerning the following question:
Hi all, I am hoping to get some feedback on what has troubled me for over a week now. I'm trying to open a bunch of files (I'm using four files as a test case) and read their contents into 2D arrays. The files looks like this:
1 2 3 4 5 6 7 8 9
I've written a script to open the files, read them line by line and then split them. When I try to print element [0][1] from each matrix in each file, I get the same number four times. This number is indeed element [0][1] but only from the first file, it's as if it ignores the rest of the files. Does anyone have any idea why this is wrong?
#/bin/perl/ use strict; use warnings; use autodie; my $molec = "1ac6"; my $cluster; my $times; my $input; my @list; my $list; my $line; my $path = "/media/RAIDstorage/home/athina/dist-analysis/${molec}/time +series/test"; my @files; @files = `ls $path\/$molec-times*`; foreach (@files) { /${molec}-times-(\d+)-clust(\d{1})/; $times = $1; $cluster = $2; open $input, '<', "$path\/${molec}-times-${times}-clust${cluster}.ou +t" or die $!; while ($line = <$input>) { chomp $line; #next unless $. > 4; push @list, [split/\s+/, $line]; }#while close $input; print "$list[0][1] \n"; }#foreach
|
|---|