in reply to Re^3: Flatten sparse AoA
in thread Flatten sparse AoA
My code is just a special case.A very, very special case. In your defined (@$_), you are trying to derefence $_ unconditionally. Considering you are using strict, this only succeeds in three cases: if $_ is an array reference, if $_ is an object with overloaded array dereferencing, or if $_ in undefined (but not in the general case, it seems only defined @$var, with $var undefined is allowed. @$var isn't, nor is defined @{+undef}). It's a run time to try to dereference a defined non-reference, or a reference that isn't an array (and doesn't have array reference overloading).
Why not just:
if you're assuming @AoA has arrayrefs and undefined values, and nothing else.@flat = map {$_ ? @$_ : ()} @AoA;
|
|---|