in reply to Tidy up conditions

You could use the short-cut behaviour of boolean operators like this:
$level = $access{$item} || $item =~ /^([^:]+):/ && $access{"$1:*"} || $access{'*'} || 0;
Note that this assumes your %access hash does not contain boolean false values, as your initial solution did. To actually check for the presence of these keys in the hash, the exists function will help.

Replies are listed 'Best First'.
Re^2: Tidy up conditions
by tel2 (Pilgrim) on Mar 19, 2015 at 02:01 UTC
    Thanks heaps for that, Martin!  Awesome answer!  Concise, yet...functional.

    I don't understand your concern about boolean false values, though. Could you give me an example which would make your code fail, please?

    Thanks again.
    Tel2

      my %hash = (0=>'that was false', ''=>'oops false too', 42=>'So very true');

      The first two keys there evaluate to false, and would cause a problem with the code.

        OK - thanks SJ,

        I had thought that when Martin said "boolean false values", he literally meant hash values, as opposed to hash keys, which is why I questioned it, but I guess he meant values in the more general sense (i.e. keys in this case).