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
In reply to Re: exiting a for loop
by GrandFather
in thread exiting a for loop
by velocitymodel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |