hehenoobhehe has asked for the wisdom of the Perl Monks concerning the following question:
I'm using such an excellent reference right now, that even the book samples dont work. All pun intended
Referring to and it says this:
"The x option tells the Perl interpreter to ignore all white space unless preceded by a backslash. As with the pattern-matching operator, ignoring white space makes complicated string patterns easier to read.
$string =~ s/\d{2} ([\W]) \d{2} \1 \d{2}/$1-$2-$3/xThis converts a day-month-year string to the dd-mm-yy format.
Now the question is this: These special built in variables namely $1, $2 that store the value of pattersn in parentheses SHOULD in theory match the pattern
([\W])
So obviously, $1,$2,$3 contain just the value "/", so how is this string substitution to work?
For all purposes (as I understand it) THIS should work: $string =~ s/(\W)/-/x;
Am I missing something here?
Thanks.Edited by castaway - added code tags.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: String Substitution Operator
by TheHobbit (Pilgrim) on Oct 23, 2003 at 09:10 UTC | |
Re: String Substitution Operator
by davido (Cardinal) on Oct 23, 2003 at 08:23 UTC | |
by hehenoobhehe (Novice) on Oct 23, 2003 at 08:42 UTC | |
by hehenoobhehe (Novice) on Oct 23, 2003 at 08:47 UTC | |
by Roger (Parson) on Oct 23, 2003 at 09:01 UTC | |
by Aragorn (Curate) on Oct 23, 2003 at 09:05 UTC |