develooper Front page | perl.perl6.language | Postings from May 2005

Re: reduce metaoperator on an empty list

Thread Previous | Thread Next
May 20, 2005 06:19
Re: reduce metaoperator on an empty list
Message ID:
>>>>> "Randal" == Randal L Schwartz <> writes:

Randal> For example, if I wanted the identity hash (where all values are 1,
Randal> but keys are original list elements), I could do:

Randal> my %hash = @somelist.inject({}, { $^a{$^b} = 1; $^a });

And yes, I know I can spell this as:

my %hash = ({}, @somelist).reduce({ $^a{$^b} = 1; $^a });

But it puts things all in the wrong place for me. :)

Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<> <URL:>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See for onsite and open-enrollment Perl training!

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About