in reply to Reading hash
So, it sounds like you want to iterate over a hash and issue the commands contained therein. If the keys are known to you, and it appears that they are, there is no need to worry about order. You can simply step through each known key one at a time. What you want is something more like:$VAR1 = 'ARRAY(0x182ae14)'; $VAR2 = undef; $VAR3 = 'ARRAY(0x1b83664)'; $VAR4 = [ 'DES', 'Step2', 'CMD', 'rm file1' ];
Which results in a data structure that looks like:my %better_cfg = (); $better_cfg{'DES'}{'Step1'} = "cp file1 file2"; $better_cfg{'DES'}{'Step2'} = "rm file1"; $better_cfg{'DES'}{'Step3'} = "vi file2";
$VAR1 = 'DES'; $VAR2 = { 'Step2' => 'rm file1', 'Step1' => 'cp file1 file2', 'Step3' => 'vi file2' };
If in fact you do not know the value of what will be the inner hash keys (step1, step2, step3), then you don't need to be using a hash at all. Simply read the values from the file into a hash in order, and then iterate over them in that order.my $step1 = $better_cfg{'DES'}{'step1'}; my $step2 = $better_cfg{'DES'}{'step2'}; my $step3 = $better_cfg{'DES'}{'step3'};
|
---|