Carl Mäsak wrote:
Andy (>):
map?

perl6 -e 'my $x = :a<5>; say $x.map( {  .value / 10} ).fmt("%s")'

Yes, sure. That'll print a tenth of the value of $x. The '.fmt("%s")'
is a no-op in this case.

// Carl
Not entirely a no-op. Thus
$perl6
> my $x=:a<5>; say $x.map({.value/10}).fmt("the value is %s%%")
the value is 0.5%

But we have lost the .key part of the pair

> my $x=:a<5>; say $x.map({.value/10}).fmt("key %s val %s")
Null PMC access in get_string()

Still, even if we could do something like (which we cant with rakudo, not sure if this is possible in perl6 in principle) say $pair.map({.key => .value*100/$count}).fmt("Candidate %s has %s percent of vote");

would it be more elegant than
printf("Candidate %s has %s percent of vote\n",$pair.key,$pair.value*100/$count);

I dont think so.

Reply via email to