why does outputting the variable "$size = @keys;" the numerical value 3 output?(Perl)

my %data = (-hund => 12, -katze => 14, -maus => 16, -kuh => 18);

my @keys = keys %data;
my $size = @keys;
print "$size\n";

Why is the number of keys displayed when the variable $size is output?

>Solution :

That’s because scalar assignment evaluates the right hand side in scalar context. An array returns the number of its elements in scalar context. See perldata.

Leave a Reply