I've just written some code to do the following:
$item will contain a string in the format 'X:Y'.
First I test if 'X:Y' exists in the hash, and if so, put the hash's value into $level.
Failing that, I test if 'X:*' exists in the hash, and if so, put the hash's value into $level.
Failing that, I test if '*' exists in the hash, and if so, put the hash's value into $level.
Failing that, I set $level = 0.
Here's the code I wrote to achieve the above:
if ($level = $access{$item}) # Assignment & test for existance {} # Not very tidy looking, IMHO elsif ($item =~ /^(.+):.+/ and $level = $access{"$1:*"} ) # Assignmen +t & test for existance {} # Not very tidy looking, IMHO else { unless ($level = $access{'*'}) # Assignment & test for existance { $level = 0 } }
The above code seems to be doing the job, and I'm not totally unhappy with it, but I'm wondering if there's a tidier or more concise way to write it, e.g. avoiding the empty '{}', and anything else you can suggest.
Note, the above was written without strict or warnings, and I'll be leaving it that way, despite the fact that it's against your religion. 8)
Thanks for your time.
Tel2
In reply to Tidy up conditions by tel2
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |