Alfie,<br><br>The + was missing in your previous email. I put it in here and it worked as advertised:<br>map {<br>    
my $f = $_;<br>    
+{     #<<<<<<<<<<<<<<<<<<--- HERE<br>    
    
map {<br>
    
    
    
$f->can($_) ? ( $_ => $f->$_() ) : ()<br>
    
    
} @fields<br>
    
}<br>
} @foos<br><br><br><div class="gmail_quote">On Wed, Oct 5, 2011 at 7:42 PM, Alfie John <span dir="ltr"><<a href="mailto:alfiejohn@gmail.com">alfiejohn@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

Also, you could have reduced it down by returning a hashref on the<br>
truth side of the ternary:<br>
<div class="im"><br>
  map {<br>
    my $f = $_;<br>
    map {<br>
</div>      $f->can($_) ? { $_ => $f->$_ } : ()<br>
    } qw( label name html )<br>
  } @fields<br></blockquote><div><br>Pretty sure this wouldn't work. A hashref can't be assigned as the key of another hashref (well technically it can but it's not very useful - I think it would just stringify to HASHgobbledigook).<br>

 </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br>
It's a shame you can't access hidden scopes and you need to create a<br>
temporary variable like $f here. Maybe Perl needs a way of accessing<br>
outer block values e.g.:<br>
<br>
  map {<br>
    map {<br>
      $_^->can($_) ? { $_ => $_^->$_ } : ()<br>
    }<br>
  } @fields<br></blockquote><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
The $_^ is $_ but one level higher (e.g. git's HEAD^ vs HEAD). But<br>
since having multiple levels would look ugly (e.g. $_^^^ for 3 levels<br>
out, maybe we also need a postfix operator like $_@ which is an array<br>
containing the all of the $_ values for each level:<br>
<br>
  $_@ = ( $_, $_^, $_^^, $_^^^ );<br>
<br>
But this wouldn't just be for $_, it would work on all variables. That<br>
way, when you local a variable, you can still access the hidden values<br>
too. Perl already stores their values.<br>
<br>
Thoughts?<br>
<font color="#888888"><br>
Alfie<br></font></blockquote><div><br>Because Perl really needs more special variables so that we don't have to bother naming anything ourselves.<br>
  
<br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><font color="#888888">
</font><div><div></div><div class="h5"><br>
On Wed, Oct 5, 2011 at 7:24 PM, Alfie John <<a href="mailto:alfiejohn@gmail.com">alfiejohn@gmail.com</a>> wrote:<br>
> Sorry... read my email during dinner.<br>
><br>
> Here is what I did as a test:<br>
><br>
>  #!/usr/bin/perl;<br>
><br>
>  use warnings;<br>
>  use strict;<br>
><br>
>  package Foo;<br>
><br>
>  use base 'Class::Accessor';<br>
><br>
>  my @fields = qw{ label name html };<br>
>  Foo->mk_accessors( @fields );<br>
><br>
>  sub new {<br>
>    my $self = bless {}, $_[0];<br>
><br>
>    foreach my $field ( @fields ) {<br>
>            $self->$field( $field );<br>
>    }<br>
><br>
>    return $self;<br>
>  }<br>
><br>
>  my @foos = map { Foo->new() } 1..3;<br>
><br>
>  use Data::Dumper; warn Dumper([<br>
>          map {<br>
>                  my $f = $_;<br>
>                  {<br>
>                          map {<br>
>                                  $f->can($_) ? ( $_ => $f->$_() ) : ()<br>
>                          } @fields<br>
>                  }<br>
>          } @foos<br>
>  ]);<br>
><br>
> It looks essentially the same as what you were running. This should output:<br>
><br>
> $VAR1 = [<br>
>          {<br>
>            'html' => 'html',<br>
>            'name' => 'name',<br>
>            'label' => 'label'<br>
>          },<br>
>          {<br>
>            'html' => 'html',<br>
>            'name' => 'name',<br>
>            'label' => 'label'<br>
>          },<br>
>          {<br>
>            'html' => 'html',<br>
>            'name' => 'name',<br>
>            'label' => 'label'<br>
>          }<br>
>        ];<br>
><br>
> Take out the + and you get:<br>
><br>
> $VAR1 = [<br>
>          'label',<br>
>          'label',<br>
>          'name',<br>
>          'name',<br>
>          'html',<br>
>          'html',<br>
>          'label',<br>
>          'label',<br>
>          'name',<br>
>          'name',<br>
>          'html',<br>
>          'html',<br>
>          'label',<br>
>          'label',<br>
>          'name',<br>
>          'name',<br>
>          'html',<br>
>          'html'<br>
>        ];<br>
><br>
> After looking at yours, it looks like the problem was the trailing<br>
> semi colon after the qw[} :)<br>
><br>
> Alfie<br>
><br>
> On Wed, Oct 5, 2011 at 5:44 PM, Toby Corkindale<br>
> <<a href="mailto:toby.corkindale@strategicdata.com.au">toby.corkindale@strategicdata.com.au</a>> wrote:<br>
>><br>
>> On 05/10/11 17:38, Alfie John wrote:<br>
>>><br>
>>> Whoops. That qw{} was in my test code.<br>
>>><br>
>>> I added the + on the block and it worked for me.<br>
>><br>
>> That is weird; I tried prefixing a + symbol to both the left-hand-curly-braces in the maps (one at a time), to no avail!<br>
>><br>
>> This is Perl 5.14.1..<br>
><br>
_______________________________________________<br>
Melbourne-pm mailing list<br>
<a href="mailto:Melbourne-pm@pm.org">Melbourne-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/melbourne-pm" target="_blank">http://mail.pm.org/mailman/listinfo/melbourne-pm</a><br>
</div></div></blockquote></div><br>