>Searches a string for a pattern, and if found, replaces that pattern with the replacement text and returns the number of substitutions made. Otherwise it returns false (specifically, the empty string).

Thank all.

Actually I read the part about s/// for many times but didn't notice about that......
The reason for that is:
1. most of the time we use $string =~ s/($pattern)/($sth)/;
2. In this case, newbie will ask: How can I get the number of substitution made?
3. And traditional programming language not prefer guys play the tricks of precedence (like Java, VB)
4. But the script guys are (and actually C of geeks)
5. When I becoming a script guys, I start to treat the "$string =~ s/($pattern)/($sth)/;" is the expression with a return value.(we should have the concept of expression can have return value - that is not the case of Java!)
6. Assignment have very low precedence, just little more than the list operator and alphabet and, or 6. Then I get it works:

$s = "Hi Hey Man, I got the enlightenment HERE!"; $cnt = $s =~ s/H/M/g; print "$cnt\n";
Result: 3

We REALLY need better tutorial, from the point of view of the non-scripting programming, they are really 2 different world.

And

Some part of the perl doc give me the feeling of the conf file of sendmail: If I am professional and remember everything, I don't need documentation at all.

If you are interested in making perl documentation better, documentation not only explaining the function behaviour, it should include some advance usage and example - plain text doesn't explain anything in most of the time. The code can express the idea better.


In reply to Re^2: Replacement regular expression which return the number of replacement it does by Anonymous Monk
in thread Replacement regular expression which return the number of replacement it does by Anonymous Monk

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.