Hello Monks after yesterdays foolish question - well the question wasn't foolish it was the dolt asking!! - I've a slightly more complex poser. I've a list of subroutines that are to run as part of a daily script. If one of them fails we want to automate the re-running of this script without editing it. I've got the mechanism for doing this unfortunately I can't get any of the subroutines to execute! The subroutine names are held in a hash table :-
my %scripts = (
"010" => {
sub => "ACC_GET_STEP",
step => '010',
},
"020" => {
sub => "ACC_PUT_STEP",
step => '020',
},
"030" => {
sub => "ACC_GET_STEP",
step => '030',
},
);
(The above is a cut down version of the hash values as there are also anonymous entries for the parameters required set up at run time). Now I know that part of the problem is being caused because I'm using the strict pragma. I know how to create a reference to a hash table but an entry to a hash within the hash table?
Can't use string ("ACC_PUT_STEP") as a subroutine ref while "strict re
+fs" in use
at xxrc_test_putstep.pl line 211.
However even if I remove the strict pragma this code still fails.
SCRIPT:
for $script (sort keys %scripts) {
next SCRIPT if ! defined $scripts{$script} {execute} ;
$step = $scripts{$script} {step} ;
$sub = $scripts{$script} {sub} ;
if ($script == '020') {
print "\n\tRunning Step :: $step Sub :: $sub\n" ;
$result = system(&$sub($file, $step)) ;
if ($result) {
print "\n\tFailed!\n" ;
}
else
{
print "\n\tSucceeded!\n" ;
}
}
}
I can think of some alternative - long long winded - ways of re-writing this without using a hash table at all but would like my code to be more concise. Any suggestions?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.