Hi again Martin,
I've incorporated the // in my code like this:
$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.
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, details, 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, summary, 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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.