在列表上下文中分配哈希有什么区别?
我必须表达:
%MON = months => 1, end_of_month => 'limit'; # months => undef
%MON = ( months => 1, end_of_month => 'limit' );
为什么第一个表达式只产生一个months带undef值的键?它们之间有什么区别?
回答
参见perlop。=优先级高于=>
%MON = months => 1, end_of_month => 'limit';
相当于:
(%MON = "months"), 1, "end_of_month", "limit"
尽管:
%MON = ( months => 1, end_of_month => 'limit' );
是:
%MON = ("months", 1, "end_of_month", "limit")