anniyan has asked for the wisdom of the Perl Monks concerning the following question:
Monks i have hash in which i have 'Process' as key and 'Order' as value.
Key Value PR1 2 PR2 4 PR3 1 PR4 3
I want to do the processing of subroutines according to the precedence order given in the hash. For example in the above hash the 'PR3' should be executed first and 'PR1' second and so on. So in the following code, third subroutine should be processed first and first subroutine should be processed second and so on without changing the subroutine name. How to achieve this?
$input = &process1 ($input) $input = &process2 ($input) $input = &process3 ($input) $input = &process4 ($input)
I can achieve this by using the subroutine name as a key in the above hash and can call the subroutines after sorting as shown below. But i want the process name as shown above like '&process1'... and should not be changed to '&PR1'.... as i have tried below.
The way i tried one way (here i have changed subroutine name as per th +e key in the hash, which i don't want): for (sort keys %po) { $input = &$_ ($input); }
I think that is not the correct way. Is there any module or any other way to do this? I can also achieve by writing combination of four subroutines with different orders but i know that is not correct method.
The second way i tried but not correct (just i gave a try): for (keys %po) { $input = &process1 ($input) if (po{$_} == 1); $input = &process2 ($input) if (po{$_} == 2); $input = &process3 ($input) if (po{$_} == 3); $input = &process4 ($input) if (po{$_} == 4); }
Regards,
Anniyan
(CREATED in HELL by DEVIL to s|EVILS|GOOD|g in WORLD)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Process order
by Zaxo (Archbishop) on Jun 09, 2006 at 11:19 UTC | |
by anniyan (Monk) on Jun 09, 2006 at 11:27 UTC | |
by ikegami (Patriarch) on Jun 09, 2006 at 14:39 UTC | |
|
Re: Process order
by davorg (Chancellor) on Jun 09, 2006 at 11:50 UTC | |
|
Re: Process order
by dsheroh (Monsignor) on Jun 09, 2006 at 15:17 UTC | |
|
Re: Process order
by kwaping (Priest) on Jun 09, 2006 at 14:41 UTC | |
by ikegami (Patriarch) on Jun 09, 2006 at 16:15 UTC | |
by anniyan (Monk) on Jun 09, 2006 at 15:19 UTC |