Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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 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?

In reply to Referencing a hash of hashes by Ronnie

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • 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, 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, 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (2)
    As of 2020-04-10 04:09 GMT
    Find Nodes?
      Voting Booth?
      The most amusing oxymoron is:

      Results (49 votes). Check out past polls.