Can the empty list be in scalar context?

前端 未结 2 1050
谎友^
谎友^ 2021-01-13 09:50

There is a lie that a list in scalar context yields the last element of the list. This is a lie because (as the saying goes) you can\'t have a list in scalar context. What

2条回答
  •  北恋
    北恋 (楼主)
    2021-01-13 10:06

    It's more like a valueless expression which is equivalent to undef. Some more examples:

    $ perl -we 'print scalar( () )'
    Use of uninitialized value in print at -e line 1.
    
    $ perl -we 'print 0+()'
    Use of uninitialized value in addition (+) at -e line 1.
    

提交回复
热议问题