Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I've had code which uses substr($foo, n, n) = ''; as an rvalue. And I'm sure others have had code which used this too. If this usage is considered a bug and Perl was resultingly changed, then this code will be broken.

Eh? Are you serious? Then, please tell, what is this snippet supposed to do? Shouldn't you have used the 4-argument substr() instead?

IMO, the value of an assignment is, commonly, what is assigned. This behaviour deviates from that generic rule in a very bizarre way: it does not return the new value, nor the old one. It just looks totally unreliable to me.

And this code wasn't written on a bug - it was written on undefined behaviour. As such, then any change to the perl implementation should be considered a core language change.

No way José. A change in previously undefined behaviour is called an improvement on the specification. You should never ever depend on undefined — or unspecified, behaviour. It is the prerogative of the Perl Porters to change that behaviour without any good reason.

And changing the behaviour so that in some way it would start to make sense, either in line with the rest in the language and returning the newly assigned value, or returning the replaced value, which would be inconsistent with the rest but which might be very handy; well: these make sense. To me, anyway.

I don't think your idiom is used that much.


In reply to Re: A Bug in the Documentation or in Perl? by bart
in thread [substr] anomaly or mine? by BrowserUk

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



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-03-28 17:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found