Because $$_ is a symbolic reference, I'm forced to countermand strict 'refs', but this is a rare, legitimate use of symbolic references, don't you think?
I agree. Though I most of the time just use Symbol's qualify_to_ref, an oft-forgotten very handy routine, I think using $$_ is clearer in this simple case. But I'd try to limit the scope as much as possible, and usually that involves a do { ... } construct.
Here I've used (as in my original reply) that map and grep can take an expression instead of a block, so note the comma after the do block. I also check the match variables instead of the indices for definedness. It just felt nice. (In the first reply I had to check the index first.)return grep defined, map do { no strict 'refs'; $$_ }, 1 .. $#- ;
I'm not exactly sure why I used a BEGIN block. It seems right. Is it?
In this case it's a matter of taste. You don't need it, but there are some possible benefits in the future. Personally I stay away from them until I need them (and I rarely do). That way I know the code needs special care when I do see them in my own code. In either case, I'd keep the curly blackets to limit the scope of $bates_number_pattern.
lodin
In reply to Re^3: Matching Multiple Alternative Patterns and Capturing Multiple Subexpressions
by lodin
in thread Matching Multiple Alternative Patterns and Capturing Multiple Subexpressions
by Jim
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |