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:

  1. it replaces only the first not-word character it founds in $string: use the /g option to solve this problem
  2. it replaces any not-word character, not just slashes.

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


Leo TheHobbit

In reply to Re: String Substitution Operator by TheHobbit
in thread 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.