in reply to Task scheduling using perl
So now, to see if X requires Y, you can just do exists $deps{$X}->{$Y}, or to list the deps (1 level) do keys %{$deps{$X}} . From there you can loop through listing dependencies or make a recursive rountine to find all levels (but be very careful of the cyclic deps).%deps = ( 1 => { 2 => undef, 3 => undef }, 2 => { 2 => undef, 4 => undef }, 3 => { 1 => undef, 4 => undef }, 5 => { 2 => undef, 3 => undef }, );
my %deps; while(<STDIN>){ my @cols = split; my $task = shift @cols; $deps{$task}->{$_} = undef for @cols; # or another way: %{$deps{$task}} = map { $_ => undef } @cols; }
|
|---|