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/x

This 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.


In reply to String Substitution Operator by hehenoobhehe

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.