Hello again Wise Monks,

I'm trying to read multiple files using @ARGV and then split them into columns and print the matrices. Then (if this ever works - I'm desperate at this point) I hope to do maths on the matrices. I have added comments at relevant places in the code, where I'm focusing my attention to solve my three problems - described further down.

I've tried all day to create a short self-contained example with dummy data but my skills are more limited than I thought - facing compilation errors literally all day and now at midnight I've given up. In that case and because I'm desperate for some feedback, I have just posted my code as it is. I hope you can find a few minutes and take a look.

My problems are three:

1. intuitively, I would think that the two for loops should enclose the whole code and close at the very end of the script. However when I did that, printing @ARGV returned wrong results. When I closed the for loops right after pushing into @ARGV, then printing @ARGV returned the correct result. Any explanation of this behaviour would be greatly appreciated, I can't figure it out at all.

2. print "@columns \n"; prints all files BUT ignores $nextUnless. Why?

3. print "$list[$a][$b] "; prints only first file and nothing else

. Does that mean that it's ignoring what's in @ARGV?

I would appreciate any pointers and I apologise for the lack of a proper example. Any feedback / insights would be immensely appreciated, Thank you so much in advance.

#!/bin/perl/ use strict; use warnings; my $molec1 = "molec1"; my $molec2 = "molec2"; my $input1; my $input2; @ARGV = ();; my $i; my $j; my $path = "/store/group/comparisons"; my $line; my @columns; my $nextUnless = 2; # nr of lines to skip my $CountLines = 0; # total nr of lines in all files for ($i=1; $i<=3; $i++) { open $input1, '<', "$path\/File-${molec1}-cluster${i}.out" or die $! +; push @ARGV, "$path\/File-${molec1}-cluster${i}.out"; } for ($j=1; $j<=2; $j++) { open $input2, '<', "$path\/File-${molec2}-cluster${j}.out" or die +$!; push @ARGV, "$path\/File-${molec2}-cluster${j}.out"; } print "@ARGV \n"; # for testing; indeed correct files are printed ## now split and print my @list; my $list; my $a; my $b; while ($line = <>) { $CountLines += 1; next unless $. > $nextUnless; chomp $line; $line =~ s/^\s+|\s+$//g; push @list, [split/\s+/, $line]; @columns = split /\s+/, $line; print "@columns \n"; ## problem: prints all columns from specifi +ed files but ignores the $nextUnless specification - why? } close $input1; close $input2; for ($a=0; $a<=$#columns; $a++) { for ($b=0; $b<=$#columns; $b++) { print "$list[$a][$b] "; ## problem: prints only first file ($i +=1) } print " \n"; }

In reply to reading files in @ARGV doesn't return expected output by fasoli

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.