a few comments on your script (some of which have already been made by other monks).
In your two nested for loops, you're opening files using $input1 and $input2 file handles, but you're never using these file handles. So this is useless. Even if it were not useless (i.e. if you had some code to read from them), it would still not work properly, because opening a file handle with the same name would close the one you've opened before.
With your nested for loops, you're using the second set of data 3 times (one for each iteration over the first set of data). That's certainly not what you want. And that's why you don't get your expected result when printing @ARGV. You most probably need separate loops.
You don't need to escape the slashes in your path.
Even though it is possible to do so, you should probably not use the while ($line = <>) { syntax because it confuses matters. In particular, $. will not be properly reset, so that your $nextUnless conditional will work properly only for the first file.
The @columns array will be clobbered with new values each time through the while loop. You may not care if you only want to print it out in the next line, but since you're using @column in the final for loop, I stringly suspect this is wrong. I am not sure, however what you need there, since you haven't shown what your data looks like.
The Data::Dumper module may help you check the content of your data structures.
This is an attempt at correcting the first part of your program (the part managing files), I can't help you with the second part without having seen the data (and the expected result).
In brief, I haven't tested that (not possible without any data), and this is not the end of it (you need to fix the thing about @columns in the while loop and probably to change the last for loop, but this should get you much closer to what you need.use strict; use warnings; use Data::Dumper; my $molec1 = "molec1"; my $molec2 = "molec2"; my $input1; my $input2; my $path = "/store/group/comparisons"; my @files; my $line; my @columns; my $nextUnless = 2; # nr of lines to skip my $CountLines = 0; # total nr of lines in all files for my $i (1..3) { push @files, "$path/File-${molec1}-cluster${i}.out"; } for my $j (1..2) { push @iles, "$path/File-${molec2}-cluster${j}.out"; } print "@files \n"; # for testing; are correct files printed? ## now split and print my @list; for my $file (@files) { open my $FH, "<", $file or die "Cannot open $file $!" while ($line = <$FH>) { $CountLines += 1; next unless $. > $nextUnless; chomp $line; $line =~ s/^\s+|\s+$//g; push @list, [split/\s+/, $line]; @columns = split /\s+/, $line; # this is most probably wrong, m +ay be you need to push a reference, as you did in the previous line } close $FH; } print Dumper \@list; # check that the content of @list is what you exp +ect # ...
Please, PLEASE, show a sample of your data (and expected result).
Update: I had forgotten to change @ARGV to @files in the second ($j) for loop. Fixed now.In reply to Re: reading files in @ARGV doesn't return expected output
by Laurent_R
in thread reading files in @ARGV doesn't return expected output
by fasoli
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |