Re: Transform hash key?



>>>>> "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
.



Relevant Pages

  • Re: HOWTO: Using .Det sections
    ... Please do not send e-mail directly to this alias. ... I have included these registry keys in my own INF, ... The PreCopySection is simply setting the NoSetupUI ...
    (microsoft.public.development.device.drivers)
  • Re: Mail merge - nicknames
    ... keys in the To: field) and see if the alias ... I would disagree. ... The .NK2 file is used by the autocompletion function of ...
    (microsoft.public.outlook)
  • Re: Registry question ..
    ... the keys are the same and the semantics are the same. ... Please do not send e-mail directly to this alias. ... Does Windows Vista driver has the same driver key of hardware, ... Another question should Windows service be an user mode or kernel mode ...
    (microsoft.public.development.device.drivers)
  • Re: Pirated XP
    ... Thanks again for sharing your story. ... :> Alias, I actually know of cases with people in the past with people using ... :> the Windows Update tells them they must contact Microsoft because their ... not reactivate to use the new keys. ...
    (microsoft.public.windowsxp.general)
  • Re: D3 ODBC Problem
    ... That phrase "accepted wisdom" reminds me of another party deriding complex keys and saying did I not realise that the accepted wisdom was to use random numeric keys for all Pick data. ... We did some work recently on a banking system that did not have decent standard edit facilities so the first thing I did before we cut a line of operational code was to write an edit routine that we used at all times. ... I regard leading zeroes on numbers as even more stupid than case sensitivity and edit them out, anyone who has seen the chaos caused by false emergency calls in Australia would understand - the emergency number is triple zero and the area codes start with zero, so what happens is people in an office dial zero to get a line, followed by another zero for the area code, glance at the number to double check and promptly enter another zero. ...
    (comp.databases.pick)