in reply to Re^2: Shortest way to replace a string
in thread Shortest way to replace a string

The spec was "shortest" and that's 10 keystrokes longer; and certainly no more efficient :)


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^4: Shortest way to replace a string
by hdb (Monsignor) on Sep 12, 2013 at 05:34 UTC

    Short? How about this?

    s/^(30\.00).*? /$1.00.00 /;

    UPDATE: Added the missing space in the "replace" bit.

      s/^(30\.00)\S+/$1.00.00/;

      is two fewer.

Re^4: Shortest way to replace a string
by choroba (Cardinal) on Sep 11, 2013 at 23:24 UTC
    It does not match ٧, though.
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      It does not match ٧, though.

      Deliberately so.

      The day anyone shows me a real program doing math with non-Hindu-Arabic numerals, I'll consider that as a requirement.

      And then disregard it completely unless it is explicitly specified.

      In just the same way that I do not walk around permanently looking up -- just in case an iceberg should fall from the sky -- I do not program to cater for marginal, statistically unlikely, possibilities, unless there is some realistic expectation that they may occur.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.