Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading