in reply to •Re: How to flatten an x-dimensional array?
in thread How to flatten an x-dimensional array?
Given the pattern of unshift's and shift's in your code, you might or might not hit this problem. But still for a single reverse you can use the guaranteed efficient pop/push pair instead of shift/unshift:
sub flatten { my @flattened; # Will be in reverse order while (@_) { my $last = pop; if (UNIVERSAL::isa($last, "ARRAY")) { push @_, @$last; } else { push @flattened, $last; } } return reverse @flattened; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
•Re: Re (tilly) 2: How to flatten an x-dimensional array?
by merlyn (Sage) on Mar 12, 2002 at 20:23 UTC | |
by tilly (Archbishop) on Mar 12, 2002 at 20:59 UTC |