My personal choice for "strings that can be present or empty" instead of "strings that can be present or undefined" is to allow for that in the regular expression as well (at the cost of some backtracking):
my ($a, $b, $c, $d) = 'abcd' =~ /(w|)(x|)(y|)(z|)/; print "$a $b $c $d";
This approach will need some additional care if the matches for w and x could overlap for example. Also, some anchoring might be needed to make certain that something is matched at all, as that regular expression can easily "match" by matching an empty string at the beginning of the match target.
In reply to Re: Idiom for setting variables to empty string if capture is undefined?
by Corion
in thread Idiom for setting variables to empty string if capture is undefined?
by nysus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |