[Melbourne-pm] Nested maps returning hash references
Toby Corkindale
toby.corkindale at strategicdata.com.au
Tue Oct 4 23:42:56 PDT 2011
On 05/10/11 17:34, Alfie John wrote:
> Hey Toby,
>
> I think there are two problems here:
>
> - Andrew was right. Put a + in front of the block
> - can($_) in the second block is being called on the qw{} and not on
> an object
In case people want working test code, here is some below.
By the way, I was trying to put the + on line 11 below, to no success,
but perhaps you mean a different {?
(I'm picking the, umm, third that occurs in the whole program, or second
within the map..)
#!/usr/bin/env perl
use 5.14.1;
use warnings;
use Data::Dumper;
my @fields = map { Foo->new($_) } qw(bing bang bong);
my $foo = [
map {
my $f = $_;
{
map {
$f->can($_) ? ($_ => $f->$_) : ()
} qw(label name html);
}
} @fields
];
say Dumper($foo);
package Foo;
sub label { shift->{label} }
sub new { bless { label => $_[1] } }
1;
More information about the Melbourne-pm
mailing list