[Melbourne-pm] Nested maps returning hash references
Toby Corkindale
toby.corkindale at strategicdata.com.au
Tue Oct 4 22:43:43 PDT 2011
It's worth noting that the following *does* work.. It's just uglier :(
map {
my $f = $_;
my $perlsucks = {
map {
$f->can($_) ? ($_ => $f->$_) : ()
} qw(label name html)
};
$perlsucks
} @fields;
On 05/10/11 16:34, Toby Corkindale wrote:
> OK, this is doing my head in.
>
> I have two map functions that work perfectly well on their own:
>
> map {
> $f->can($_) ? ($_ => $f->$_) : ()
> } qw (label name html);
>
> map {
> {
> label => $f->label,
> name => $f->name,
> html => $f->html,
> }
> } @fields;
>
>
> However when I combine them, it all goes pear-shaped, and I just get
> back one huge, flat array, rather than an array of hashes.
>
> map {
> my $f = $_;
> {
> map {
> $f->can($_) ? ($_ => $f->$_) : ()
> } qw(label name html);
> }
> } @fields;
>
>
> Any thoughts?
>
> Cheers,
> Toby
> _______________________________________________
> Melbourne-pm mailing list
> Melbourne-pm at pm.org
> http://mail.pm.org/mailman/listinfo/melbourne-pm
--
.signature
More information about the Melbourne-pm
mailing list