user2563207
user2563207

Reputation: 97

What is the meaning of this line keys(%S)=@C_fields;?

I have one general question in Perl.What is the meaning of below line

keys(%S)=@C_fields; 

Upvotes: 4

Views: 176

Answers (1)

mpapec
mpapec

Reputation: 50667

keys(%S)=@C_fields; is identical to keys(%S) = scalar @C_fields;

and from perldoc -f keys

Used as an lvalue, keys allows you to increase the number of hash buckets allocated for the given hash. This can gain you a measure of efficiency if you know the hash is going to get big. (This is similar to pre-extending an array by assigning a larger number to $#array.) If you say

keys %hash = 200;

then %hash will have at least 200 buckets allocated for it--256 of them, in fact, since it rounds up to the next power of two.

So hash %S will get number of buckets which are at least size of @C_fields array.

Upvotes: 7

Related Questions