Perl: What is the easiest way to flatten a multidimensional array?

后端 未结 7 1662
北荒
北荒 2020-12-16 13:27

What\'s the easiest way to flatten a multidimensional array ?

相关标签:
7条回答
  • 2020-12-16 14:23

    Something along the lines of:

    my $i = 0;
    
    while ($i < scalar(@array)) {
        if (ref @array[$i] eq 'ARRAY') {
            splice @array, $i, 1, @$array[$i];
        } else {
            $i++;
        }
    }
    

    I wrote it blindly, no idea if it actually works but you should get the idea.

    0 讨论(0)
提交回复
热议问题