Regular expressions are used with the split function to break up strings into a list of substrings. The converse to split is the join function, which takes a list of strings and joins them together again. No. The converse to a split is a regular expression (with matching). The idea here is that with matching you specify what you want to match and you get that as a return value ala @simpsons = "Bart Lisa Maggie Marge Homer" =~ /(\w+)/g). With split you specify all the things you don't want and you get everything else. Which one you use depends on what is more natural to specify. I'm glossing over the fact that plain regular expressions are actually even more powerful than that but that's how they compare with split anyway (which itself uses a regex as its first parameter).
If split is given a null string as a delimeter, it splits on each character in the string, and since the delimeter is nothing at all, nothing at all is thrown away. No. The empty regular expression matches at every position possible which includes between characters. This is how anchoring works. As an example, ^ normally matches the position before the first character. This is only possible if the "spaces" before, after and between characters are also places to match. So when matching "ab" with // it can match before the "a", the "a", between the "a" and the "b" and after the "b". When you actually run that the only parts that get returned in the split is the "a" and the "b".
The word "delimit" isn't spelled with an 'e' in it.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|