Duh v D'oh

Yitzchak Scott-Thoennes sthoenna at efn.org
Thu Nov 6 18:22:25 GMT 2008


On Thu, November 6, 2008 9:00 am, Nigel Rantor wrote:
> Paul Makepeace wrote:
>
>> Following on the theme from a conversation with Mark at Dim Sum today*,
>> spot the mistake I just wasted an hour on,
>>
>> my $publication_stats = [['Source', 'ID Publication', 'Article
>> count']]; foreach my $given_source (%publication_map_by_name) { push
>> @$publication_stats, [$given_source,
>> $publication_map_by_name{$given_source},
>> $article_count_by_source{$given_source}];
>> }
>>
>
> You're setting $given_source alternately to be keys and values from the
> hash  %publication_map_by_name. This probably won't end well.
>
>> If it's not staring out at you, you're possibly also a python
>> programmer. Python here arguably DWIM better than perl.
>>
>
> Does python give you the keys by default?

Pity we can't differentiate generic list context from iterator-source
context.  With the latter also having a pairlist flavor, I guess.  So
these would all "work":

    %h = %h;   # keys and values
    for (%h)   # implicit keys
    for (pairlist %h)   # no implicit keys

It's a good thing perl 6 is coming; introducing this kind of thing one
piecemeal into perl 5 could really screw it up.




More information about the london.pm mailing list