Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • TIMTOWTDI, but you don't have to jump through all those hoops, just to get one definite capture variable for every case. Just take a look at $+ [perl.org] and you'll see it was especially designed for these cases, where you have captures in alternatives and you don't know which alternative matched. So, you can just use your 2 captures regex, and simply get the one you want with $+.

    But, I think this probably is not such a good idea. You ought to strip the backslashes in those quoted strings that are just there to escape special characters (backslashes and quotes). Unless, if you always want to remove these backslashes, whether the string was quoted, or not.

    • Two upsides of using conditional match:

      • It works in multiple-capture scenarios.
      • It provides a boolean flag capture.

      The boolean flag makes it particularly nice to make the backslash stripping conditional on the presence of quotes.