in reply to Dealing with undefined captures in a substitution
Other than that, I don't know of other more elegant options.sub munge { my $str = shift; $str =~ s/^R(?:([12])|(3))?$/(${1}||"")."text".($2||"")/e; $str; }
Edit:Anonymous Monk below is correct - _if_ our regex could capture a zero for $1 or $2, we'd have to do the defined()?: approach. But 0 can't match either capture here...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Dealing with undefined captures in a substitution
by Anonymous Monk on Aug 04, 2007 at 09:55 UTC |