In a Perl script, I create a large hash (about 10 GB) that takes about 40 minutes, which contains about 100 million keys. Then I want to skip the hash keys, for example:
foreach my $key (keys %hash) {
However, this line takes 1 hour and 20 minutes! Once in the for-loop, the code goes through the entire hash at a fast pace.
Why does logging in forloop take so long? And how can I speed up the process?
, %hash, , %hash , , . , .
%hash
while (my ($key, $value) = each %hash) { , . , , .
while (my ($key, $value) = each %hash) {
, .
foreach my $k (keys %h) { print "key: $k, value: $h{$k}\n"; }
while ( ($k, $v) = each %h ) { print "key: $k, value: $h{$k}\n"; }
each
%h
keys %h
values %h
each %h
Source: https://habr.com/ru/post/1534861/More articles:How to make an excel file available for download - javaCustom VBA forms. Text box as a numeric value for a cell - vbaWPF: is there an event caused by a resource change - c #How to make an element disappear and reappear when scrolling down? - javascript.hide и .show отображать все элементы и не работать должным образом, пока пользователь не прокрутит - javascriptCentering a horizontal list in Bootstrap 3 Responsive Design - listjava.lang.RuntimeException: error: 0D0680A8: asn1 encoding procedure: ASN1_CHECK_TLEN: invalid tag - javaerror: 0c0890ba: ASN.1 encoding procedures: asn1_check_tlen: WRONG_TAG - javaQueryDsl orderBy column name - hibernateHow google.maps.geometry will be undefined? - javascriptAll Articles