Perl中的increment()和decrement( – )字符串

with perl -e’$ string =“a”; print $ string;’我们得到b,
但是用perl -e’$ string =“b”; print – $ string;’我们得到-1。

所以,如果我们可以递增为什么我们不能递减?

EDITED
自动减量运算符不是神奇的”perlop

Perl给了我们很多设施,为什么不是这个?这不是批评,但不会预期类似的操作符的类似行为?有什么特别的原因吗?

解决方法

perlop(1)解释说这是真的,但没有给出理由:

The auto-increment operator has a little extra builtin magic to it. [If applicable,and subject to certain constraints,] the increment is done as a string,preserving each character within its range,with carry[…]

The auto-decrement operator is not magical.

得到-1的原因是因为当解释为数字时,“b”变成0,因为它没有前导数字(相反,“4b”变成4)。

相关文章

1. 如何去重 #!/usr/bin/perl use strict; my %hash; while(...
最近写了一个perl脚本,实现的功能是将表格中其中两列的数据...
表的数据字典格式如下:如果手动写MySQL建表语句,确认麻烦,...
巡检类工作经常会出具日报,最近在原有日报的基础上又新增了...
在实际生产环境中,常常需要从后台日志中截取报文,报文的形...
最近写的一个perl程序,通过关键词匹配统计其出现的频率,让...