A hash of prioritised lists seems like what you need:
use warnings; use strict; my $inputdir; my %files = Prioritise_requests ($inputdir); for my $fileList (sort keys %files) { print "$files{$file}->[0]\n"; # Lowest priority file print "$files{$file}->[-1]\n"; # Top priority file } sub Prioritise_requests { my ($input_directory, $node) = @_; my %files; my $index = 1; while (1) { last if ! opendir SCAN, "$input_directory$index"; for my $filePath (grep (/^Flat_file.*\.txt$/, readdir (SCAN))) + { my ($file) = $filePath =~ m![^\\/]*$!; push @{$files{$file}}, $_; ++$index; } closedir SCAN; } return %files; }
Note that this is untested and doesn't include all the "non-issue" work of your sample code.
Updated to avoid "perpetual" loop
In reply to Re: Working with a unkown number of arrays
by GrandFather
in thread Working with a unkown number of arrays
by Win
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |