What decides the order of keys when I print a Perl hash?

前端 未结 8 1234
挽巷
挽巷 2020-12-03 19:35

activePerl 5.8 based

#!C:\\Perl\\bin\\perl.exe
use strict;
use warnings;

# declare a new hash
my %some_hash;

%some_hash = (\"foo\", 35, \"bar\", 12.4, 2.5,         


        
8条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-03 19:59

    The elements are (almost certainly) printed out in the order they appear (internally) in the hash table itself -- i.e. based on the hash values of their keys.

    The general rule to follow is to use something other than a hash table if you care much about the order.

提交回复
热议问题