Perl, convert hash to array

后端 未结 11 2106
借酒劲吻你
借酒劲吻你 2021-02-05 06:56

If I have a hash in Perl that contains complete and sequential integer mappings (ie, all keys from from 0 to n are mapped to something, no keys outside of this), is there a mean

11条回答
  •  爱一瞬间的悲伤
    2021-02-05 07:48

    Perl does not provide a built-in to solve your problem.

    If you know that the keys cover a particular range 0..N, you can leverage that fact:

    my $n = keys(%hash) - 1;
    my @keys_and_values = map { $_ => $hash{$_} } 0 .. $n;
    my @just_values     = @hash{0 .. $n};
    

提交回复
热议问题