sub Prioritise_requests { my ($input_directory, $node) = @_; my $input_directory_lowest = $input_directory."1"; my $input_directory_middle = $input_directory."2"; my $input_directory_highest = $input_directory."3"; my @lowest_priority; my @sorted_lowest_priority; my @middle_priority; my @sorted_middle_priority; my @highest_priority; my @sorted_highest_priority; opendir (LOWEST, "$input_directory_lowest") or die "Error opening directory: $!"; foreach (sort grep(/^Flat_file.*\.txt$/,readdir(LOWEST))) { push @lowest_priority, $_; } @sorted_lowest_priority = sort { -M $a <=> -M $b } @lowest_priority; closedir *LOWEST; my $request_of_interest = 'none'; opendir (MIDDLE, "$input_directory_middle") or die "Error opening directory: $!"; foreach (sort grep(/^Flat_file.*\.txt$/,readdir(MIDDLE))) { push @middle_priority,$_; } @sorted_middle_priority = sort { -M $a <=> -M $b } @middle_priority; closedir MIDDLE; opendir (HIGHEST, "$input_directory_highest") or die "Error opening directory: $!"; foreach (sort grep(/^Flat_file.*\.txt$/,readdir(HIGHEST))) { push @highest_priority,$_; } @sorted_highest_priority = sort { -M $a <=> -M $b } @highest_priority; closedir HIGHEST; if (@sorted_highest_priority) { foreach (@sorted_highest_priority){ # foreach high priority request $request_of_interest = $_; my $do_I_pick_up_request = Is_the_file_mine($node, $request_of_interest); if ($do_I_pick_up_request eq 'Y'){ my $time_to_run = Do_I_run_the_request_now ($request_of_interest); if ($time_to_run eq 'Now'){ move "$input_directory_highest/$request_of_interest", "$input_directory" or warn $!; return; } } } } if (@sorted_middle_priority) { foreach (@sorted_middle_priority){ $request_of_interest = $_; #return $request_of_interest; my $do_I_pick_up_request = Is_the_file_mine($node, $request_of_interest); if ($do_I_pick_up_request eq 'Y'){ my $time_to_run = Do_I_run_the_request_now ($request_of_interest); if ($time_to_run eq 'Now'){ move "$input_directory_middle/$request_of_interest", "$input_directory" or warn $!; return; } } } } if (@sorted_lowest_priority) { foreach (@sorted_lowest_priority){ $request_of_interest = $_; my $do_I_pick_up_request = Is_the_file_mine($node, $request_of_interest); if ($do_I_pick_up_request eq 'Y'){ #return $request_of_interest; if ($do_I_pick_up_request eq 'Y'){ my $time_to_run = Do_I_run_the_request_now ($request_of_interest); if ($time_to_run eq 'Now'){ move "$input_directory_lowest/$request_of_interest", "$input_directory" or warn $!; return; } } } } } }