in reply to String Substitution Operator
Hi,
I'd realy like to know what this reference is...
People that write that sort of things should be hung and sent to the programmers' hell, where they'll have to write useless software in VB for the eternity... (I'm doing right this now, writing useless software in VB I mean, and I can not immagine a better definition of programmers' hell).
Obviously,
$string =~ s/\d{2} (\W) \d{2} \1 \d{2}/$1-$2-$3/x
does not what that wanna be reference says. Infact, it also is semanticaly wrong, $2 and $3 being undefined in the replacement part: the matching part of the s/// operator contains only one pair of parenthesis, so that only $1 is defined.
The sobstitution you propose almost does the work. I say almost because:
a third problem (that could be disregarded) is that the /x option is useless, since there are nor spaces nor comments in the regex.
A simpler way to to that would be to use the tr/// operator, like in
$string =~ tr!/!-!;
Obvously, all this still lets you short of an useful example about how and why use the /x option in matching operators. I'm sorry, but I have none to offer to you now, may be later, when I'll be at home with all my little files at hand...
Hoping that this helps...
|
---|