simonozzy has asked for the wisdom of the Perl Monks concerning the following question:
Hello wise monks
We have a bespoke Perl scheduler that calls around 100 ETL tasks to load data into a data warehouse. The tasks are defined in a array and each taskname has it's own hash array of values which can be quite extensive, including file, time and sql dependancies.
We need to run the tasks in order of priority, but the problem is that priority needs to be a value within the taskname hash, so I can't see a way of sorting by it? I've searched a few sites for sort options but can't seem to get this to work. Below is what I've tried so far. Any ideas?
#!/usr/bin/perl -w use strict; my $tasks = { "A_Task_2" => { priority => 2, }, "A_Task_1" => { priority => 1, }, "A_Task_3" => { priority => 3, }, "B_Task_1" => { priority => 1, task_depends => [ 'A_Task_1', 'A_Task_2', 'A_Task_3', 'A_Task_4', ], }, "A_Task_4" => { priority => 4, }, }; # for my $taskname (sort keys %$tasks) # works fine for my $taskname (sort { $tasks->{priority} <=> $tasks->{priority} } k +eys %$tasks ) # not working - can you see what I'm trying to do? { my $task = $tasks->{$taskname}; print $task->{priority} , "-", $taskname, "\n" ; # works sleep(1) ; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sorting an array of hashes by a value of hash
by Ratazong (Monsignor) on Apr 13, 2011 at 11:26 UTC | |
by simonozzy (Initiate) on Apr 13, 2011 at 13:21 UTC | |
by davido (Cardinal) on Apr 13, 2011 at 16:43 UTC | |
by simonozzy (Initiate) on Apr 14, 2011 at 17:14 UTC | |
by davido (Cardinal) on Apr 14, 2011 at 17:28 UTC | |
|
Re: Sorting an array of hashes by a value of hash
by Corion (Patriarch) on Apr 13, 2011 at 11:20 UTC |