Re: Transform hash key?
- From: Uri Guttman <uri@xxxxxxxxxxxxxxx>
- Date: Tue, 31 Jan 2006 13:53:33 -0500
>>>>> "DS" == DJ Stunks <DJStunks@xxxxxxxxx> writes:
>>
>> my %h = map { $_ => 1 } ('aaa' .. 'zzz');
>>
>> cmpthese -1, {
>> map => sub { %h = map { uc $_ => $h{$_} } keys %h },
>> for => sub { $h{uc $_} = delete $h{$_} for keys %h; },
>> };
>>
>> D:\Home\asu1\UseNet\clpmisc> s.pl
>> Rate map for
>> map 12.4/s -- -60%
>> for 31.5/s 153% --
>> Nice.
DS> Would it be possible to alias the keys and edit in-place? It would be
DS> easy to do so with the values, but I'm not sure about the keys.
the values function in recent perls returns aliases to the values (which
are normal perl scalars) of the hash so you can directly mung them. but
the keys aren't normal perl values and so you can't take a reference or
alias to them. you have to deal with them indirectly via the hash's
interface which is what those two solutions do.
uri
--
Uri Guttman ------ uri@xxxxxxxxxxxxxxx -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
.
- References:
- Transform hash key?
- From: MSG
- Re: Transform hash key?
- From: A. Sinan Unur
- Re: Transform hash key?
- From: Uri Guttman
- Re: Transform hash key?
- From: A. Sinan Unur
- Re: Transform hash key?
- From: DJ Stunks
- Transform hash key?
- Prev by Date: Re: print statement creates key in hash with reference to empty array??
- Next by Date: Re: why doesn't sort properly?
- Previous by thread: Re: Transform hash key?
- Next by thread: Re: Transform hash key?
- Index(es):
Relevant Pages
|