Corion pointed to the probable most important mistake in your code. I would also add that $counter has also not been initialized (and not declared).

Your code is an perfect example of what is often called "baby Perl", i.e. code using only a small subset of the language. There is nothing derogative in this expression, quite to the contrary: beginners are encouraged to write scripts in baby Perl, this is the right way to start learning. And most monks here (including myself), perhaps all monks, have started this way.

I would like to offer a few possibly more "Perlish" ways of doing the same thing, but without trying to do too clever things:

@input = <INPUT>; $query1_name = $input[0]; $query1 = $input[1]; $query2_name = $input[2]; # ... $query4 = $input[7];
You may want to use a data structure rather than 8 variables. The eight code lines above can be replaced by:
my @query; ($query[$_]{name}, $query[$_]{content}) = @input[2*$_, 2*$_ + 1] for 0 +..3;
Which, for an @input array containing numbers fro 1 to 8, gives me the following data structure:
0 ARRAY(0x600500b60) 0 HASH(0x600500a88) 'content' => 2 'name' => 1 1 HASH(0x6005cffa8) 'content' => 4 'name' => 3 2 HASH(0x6005cffd8) 'content' => 6 'name' => 5 3 HASH(0x600635958) 'content' => 8 'name' => 7
This structure is called an array of hashes (AoH): it is an array of four elements, in which each element is a reference to a hash with two keys.

Similarly, you can change:

@query1 = split ('', $query1); @query2 = split ('', $query2); @query3 = split ('', $query3); @query4 = split ('', $query4);
to this:
$query[$_]{split_content} = [ split '', $query[$_]{content} ] for 0..3 +;
and for the lengths:
* $query[$_]{length} = scalar @{ $query[$_]{'split_content'}} for 0. +.3;
although I am not sure this is needed since you seem to be using only $length1, but this may be another bug. Now the data structure is looking like this:
0 ARRAY(0x600500b60) 0 HASH(0x6005fdbb8) 'content' => 2 'length' => 1 'name' => 1 'split_content' => ARRAY(0x600635d30) 0 2 1 HASH(0x6005d0050) 'content' => 4 'length' => 1 'name' => 3 'split_content' => ARRAY(0x60063d850) 0 4 2 HASH(0x60063d928) 'content' => 6 'length' => 1 'name' => 5 'split_content' => ARRAY(0x6006360a8) 0 6 3 HASH(0x6006359d0) 'content' => 8 'length' => 1 'name' => 7 'split_content' => ARRAY(0x600636060) 0 8
This:
while ($counter <= $length1) #...
might be better written:
for my $counter (0..$length1) { ...
which will do for you the incrementation missing in your code.

I won't go further into your code, but I would add that you should should take the habit of declaring all your variables (with the my operator) and to insert the following pragmas at the top of your programs:

use strict; use warnings;

Je suis Charlie.

In reply to Re: Parsing Multiple Alignment -- using Perl for DNA by Laurent_R
in thread Parsing Multiple Alignment -- using Perl for DNA by le_albatross

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.