http://www.perlmonks.org?node_id=541639


in reply to Re^3: Go to?
in thread Go to?

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re^5: Go to?
by McDarren (Abbot) on Apr 06, 2006 at 16:10 UTC
    question that occurs is - line 34 is setting an execute flag against each value held on the hash table?
    Well, sortof...
    The "execute" is just really a label. The line that you refer to...
    # Set everything to initially be executed for (keys %scripts) { $scripts{$_}{execute}++; }
    ..just iterates through the hash, incrementing the value of $scripts{$key}{execute} for each $key. As none of these keys exist at this point, they are created (autovivication) and their respective values are set to 1.

    So what we end up with is..

    $scripts{1}{execute} = 1 $scripts{2}{execute} = 1 etc...
    The same thing happens a little later on (on line 45)...
    for (keys %scripts) { $scripts{$_}{execute}=undef; }
    ...but here we're setting them all to undef.

    Then when we get into the main loop, the first thing we do is to test whether that key exists, and if it doesn't we skip it and move on to the next one...

    # Skip this one if we need to next SCRIPT if !defined $scripts{$script}{execute};
    Incidentally, those for loops above could be done a little more elegently (and more efficiently) with a map...
    map { $scripts{$_}{execute}++; } keys %scripts;

    Which book covers this - I've bought most of the O'Reilly books
    Perl books that I have and would recommend are: I have several others, but they are the three that I personally refer to most often.
    in the sense of different employers and the constraints that might apply depending on employer!
    Actually, I can empathise with this. I have recently changed employer and moved from an environment that was primarily *nix to one that is primarly *shudder* 'doze. And it hurts, believe me. But fortunately, I am in a position where I do have some level of control - so I'm busily replacing windows boxes with Linux ones whenever and where-ever I can ;)

    Finally...

    Sorry if the experience comment offended
    None taken. And I _was_ going to let it (and the other comments) go. But after I thought about it a bit I decided that I needed to clarify my position as I felt that I'd been misunderstood (and mis-represented).

    Cheers, and good luck with your task at hand!
    Darren :)

      In light of your excellent help I think i can safely say that I won't require a goto - other than goto the Perl books and read up on hash tables and autovivication which I can barely spell never mind comprehend! I thought you were generating an execute label/attribute in flight so to speak but wasn't aware you could do that (or what that was called)!

      Many thanks,
      Ronnie