What do you get if you evaluate a hash in scalar context?

前端 未结 5 2133
滥情空心
滥情空心 2020-12-03 07:20

Consider the following snippet:

use strict;
use warnings;

my %a = ( a => 1,
          b => 2,
          c => \'cucu\',
          d => undef,
            


        
5条回答
  •  一生所求
    2020-12-03 07:49

    From perldoc perldata:

    If you evaluate a hash in scalar context, it returns false if the hash is empty. If there are any key/value pairs, it returns true; more precisely, the value returned is a string consisting of the number of used buckets and the number of allocated buckets, separated by a slash.

    In your case, you have five values (1,2,''cucu',undef, and '321312321') that have been mapped to by eight keys (a,b,c,d,r,br,cr, and dr).

提交回复
热议问题