Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

hash

perl

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

keys(%S)=@C_fields; 
like image 824
user2563207 Avatar asked Feb 06 '15 12:02

user2563207


1 Answers

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.

like image 132
3 revs, 2 users 96% Avatar answered Nov 14 '22 15:11

3 revs, 2 users 96%