Reputation: 97
I have one general question in Perl.What is the meaning of below line
keys(%S)=@C_fields;
Upvotes: 4
Views: 176
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