Dear Monks,

At the moment this subroutine looks into folders 1, 2 and 3. It assigns files in folder 1 as having the lowest priority and will only process this file if there are no files of higher priority. I would like to update this program so that there can be any number of folders which are assigned a number. The higher the number the higher the priority. But before the program starts the program does not know how many folders there are. Please can people inform me on how best I can take this subroutine to the next level.

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 di +rectory: $!"; 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 di +rectory: $!"; 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_priori +ty; closedir HIGHEST; if (@sorted_highest_priority) { foreach (@sorted_highest_priority){ # foreach high priority requ +est $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_di +rectory" 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_dir +ectory" 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_in +terest); 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_intere +st); if ($time_to_run eq 'Now'){ move "$input_directory_lowest/$request_of_interest", "$input +_directory" or warn $!; return; } } } } } }

In reply to Working with a unkown number of arrays by Win

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.