Perl, convert hash to array

后端 未结 11 2243
借酒劲吻你
借酒劲吻你 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:23

    We can write a while as below:

    $j =0;
    while(($a1,$b1)=each(%hash1)){
        $arr[$j][0] = $a1;
        ($arr[$j][1],$arr[$j][2],$arr[$j][3],$arr[$j][4],$arr[$j][5],$arr[$j][6]) = values($b1);
        $j++;
    }
    

    $a1 contains the key and $b1 contains the values In the above example i have Hash of array and the array contains 6 elements.

提交回复
热议问题