Yes, thank you.
Update:
#!/usr/bin/perl -w
use strict;
use Data::Dumper;
$|++;
my @AoA = ( undef,
[1, 2],
undef,
[3, 4]);
my @flat = map{defined (@$_) ? @$_ : ()}@AoA;
print join (",",@flat),"\n"; # prints: 1,2,3,4
my $AoAref = \@AoA;
@flat = map{ defined (@$_) ? @$_ : () }@$AoAref;
print join (",",@flat),"\n"; # prints: 1,2,3,4
=so far prints:...
1,2,3,4
1,2,3,4
=cut
@AoA = ( undef,
[1, undef],
undef,
[3, 4]);
$AoAref = \@AoA;
# "undef" is a legal Perl value.
# to handle this idea of an undef value within
# an defined array (undef is a legal Perl value)! Yes, use grep.
#
# my map filters out "undefined references to arrays"
# within an AoA, I would use grep to filter
# that undesired "undef" value out if what is meant
# a value within in an array.
# as shown before: grep{} map{}.
My code is just a special case.
The more general case is to flatten the whole thing out and grep out the undefined values provided that if what is meant by "sparse" is that not only entire rows are missing but also columns within defined rows. "undef" is a legal Perl value and requires some kind of "grep" to "get rid of it"
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.