in reply to Re: Can you set a character in a string at a given index directly?
in thread Can you set a character in a string at a given index directly?

This one I like. I mean the example. I could not figure this out that quickly even reading the documentation. I have always thougt that substr returns something. I never thought of it as something that can set something :).
  • Comment on Re^2: Can you set a character in a string at a given index directly?

Replies are listed 'Best First'.
Re^3: Can you set a character in a string at a given index directly?
by MidLifeXis (Monsignor) on Feb 03, 2015 at 16:12 UTC

    The return value of substr is an lvalue (assuming the original string is an lvalue), which is a fancy way of saying that it can be assigned to. So, the chunk of the data returned by substr can be assigned to. The four argument version of this call is (basically) equivalent.

    substr( $string, $index, # starting from 0 1, # how many characters ) = $replacement;

    --MidLifeXis