I created a small script to take odd(n) lines from one file, evaluate if this line is a part of any line(whatsoever) from another file and then print this line and the next one (n+1) into an output file.

#!/usr/bin/perl -w use strict; use warnings; my $num_args = $#ARGV + 1; if ($num_args != 3) { print "\nUsage: ./fastqkokku fasta quala outputfile\n"; exit; } my $fasta=$ARGV[0]; my $quala=$ARGV[1]; my $out=$ARGV[2]; open FA, "< $fasta"or die "Can't open $fasta: $!"; open QA, "< $quala" or die "Can't open $quala: $!"; open OUT,"> $out" or die "Can't open $out: $!"; while (my $line = <QA>){ chomp $line; my $nextline = <QA>; while (my $compline = <FA>){ if ($compline =~ m/$line/){print OUT "$compline$nextline"; }} + } close FA; close QA; close OUT;

I repeat myself a bit here but .. well what I tried to accomplish with these while loops was > Outer loop.. iterate through all even $lines, get the odd $nextline for each of them, then for each of those $lines > Inner loop.. iterate through every line in FA, do the match and print out relevant $line$nextline combinations.

After testing the script with different input files I discovered that it will do all of those match evaluations only with the first $line of the outer loop. Is it connected to the nested-ness of those two loops. If I would eliminate the inner one and just leave my $compline = <FA>? would it then open the first line in FA over and over or would it open the n-th line of FA for each iteration of the loop ( iterations based on the QA lines) - both of these would be unsitisfactory. Can you help me to get the outer loop to iterate again, or suggest any other ways I could accomplish my goal which I have doubly described above?


In reply to Compare two files, nested while loops? Outer loop not iterating? by naturalsciences

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.