in reply to Converting array reference to list context

Insofar as I understand the (apparently edited) OP, a recursive approach also works (and is almost one line):

>perl -wMstrict -le "my @a_refs = ([1], 2, [3, 4], [5, [6, [7, 8]]], 9); ;; sub flatten { map { 'ARRAY' eq ref() ? flatten(@$_) : $_ } @_ } ;; my @flattened = flatten(@a_refs); use Data::Dumper; print Dumper \@flattened; " $VAR1 = [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ];

Note: This also works on the original example (Update (per GrandFather): as it was ultimately updated:)  ([1],[2],[3,4]) array.

Replies are listed 'Best First'.
Re^2: Converting array reference to list context
by GrandFather (Saint) on Jan 01, 2011 at 03:58 UTC

    The last line of the original code was:

    $arr_ref_new = ( [1],[2],[3,4] ) ;
    True laziness is hard work