$item = 'Test';
$level =
$access{$item} //
($item =~ /^([^:]+):/ && $access{"$1:*"}) //
$access{'*'} //
999;
print "level='$level'\n";
Unfortunately, when the regex doesn't match, it seems to short-circuit, and this is printed:
level=''
Any ideas why? I assume it's something to do with the line which contains the regex not being 'defined', but I'm not sure.
Meanwhile, I've worked around it by putting the regex first, like this:
$access{'*'} = 30;
$item = 'Test';
$item =~ /^([^:]+):/;
$level =
$access{$item} //
$access{"$1:*"}) //
$access{'*'} //
999;
print "level='$level'\n";
And I think that's working (i.e. it prints "level='30'" in the above case).
If you've got a better adjustment to this code, which doesn't involve using that regex unless needed, I'd love to see it. Otherwise, no worries - I'm pretty happy.
Thanks again. |