Increment (++) and decrement (--) strings in Perl

前端 未结 3 1449
执念已碎
执念已碎 2020-12-18 17:45

With perl -e \'$string=\"a\";print ++$string;\' we get b,
but with perl -e \'$string=\"b\";print --$string;\' we get -1

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-18 18:46

    Perl give us lots of facilities, why not this one?

    Because it is not intuitive what values should precede the "lowest" character in range. It may make sense that "A" + 1 should be "B", and that "B" + 1 should be "C". And therefore "B" - 1 should be "A". But what should "A" - 1 be?

提交回复
热议问题