Well, there is excellent stuff and terrible stuff there, and the code you posted doesn't match with the results you describe.

The good stuff is that you are using strictures, three parameter open and are reporting errors from the open statements very nicely. Well done!

The worst of the bad stuff is that your code is not indented at all! Aside from anything else that hides the next bad thing: you have nested your named subroutines inside other code. Perl lets you do that, but there is no good reason to do it (unlike some other languages). So the first thing is to move the subs out of the while loop and indent the code.

Having done that it becomes clear that there is a last statement at the end of events that can never be hit because it follows an unconditional return statement. Maybe that should be somewhere else, but it's not at all clear where.

The identifier records is used way too much. It is a subroutine name, it is an array, it is a scalar that holds a reference to an array and it looks like the array is used in two different incompatible roles as well. Very nasty indeed!

There are a bunch of other errors that I can't well advise on because I simply can't figure out what should really be happening. However, you might like to start with the following code, add some example data in place of the rubbish I've supplied, and see if you can reach a place where you can re-ask your question with something that has a better chance of working.

use strict; use warnings; my @records; my @list; my @sorted_recs; while (<DATA>) { chomp; my @tokens = split; my @record = @tokens[3, 4, 5, 6, 10, 11]; push @records, \@record; } print join (', ', @$_), "\n" for sort {$a->[3] <=> $b->[3]} @records; __DATA__ 0 1 2 3 4 5 6 7 8 9 10 11 1 1 2 2 4 5 2 7 8 9 10 11 2 1 2 1 4 5 9 7 8 9 10 11

Prints:

2, 4, 5, 2, 10, 11 3, 4, 5, 6, 10, 11 1, 4, 5, 9, 10, 11
True laziness is hard work

In reply to Re: exiting a for loop by GrandFather
in thread exiting a for loop by velocitymodel

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.