Yes. Using undef as the third argument does have that effect. I suspect Perl 6 will improve on this somewhat by being able to do:
substr $str, -1, replace => '';
This may not seem like much of an improvement, but it gets rid of the undef, which could possibly be mysterious to the uninitiated (as could lvalue substr).
Update: yikes! Using undef doesn't actually work like this (i.e. as the third arg in a Perl-5 substr). I had assumed it did, but it actually acts the same as using 0 as the third arg (at least with 5.8.0). Anyways, the lvalue behavior is stable and documented since 5.6 (possibly earlier); if undef works like this in any Perl version, I haven't seen it documented. Sorry for the foolish mistake (and for the unfounded assumption).
-
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.
|