RE: Fastest method with a hashes...

2002-05-20 Thread Jeff 'japhy' Pinyan
On May 20, Nikola Janceski said: >This returns an odd number of elements: > >my %BYNAME = map { { "$ALL{$_}" => "$_" } } keys %ALL; You've got an extra set of { } in there. The inner one makes a hash reference, so if the hash has an odd number of keys, there will be an odd number of hash refere

Re: Fastest method with a hashes...

2002-05-20 Thread Jonathan E. Paton
--- "John W. Krahn" <[EMAIL PROTECTED]> wrote: > ... > %byname = reverse %hash; Thanks John, that was the concise way to do it. Time for someone to do the benchmarks between this and the "while each" method I did. I *think* the latter will be faster (or at least less memory hungry) - but perha

RE: Fastest method with a hashes...

2002-05-20 Thread Jonathan E. Paton
> any ideas on how to create reverse hash quick? > ... while (my ($key, $value) = each %hash) { warn "Collision during inversion!" if exists $hash{$value}; $new_hash{$value} = $key; } of course, if you are doing this a lot then you need a different structure. The solution is obv

Re: Fastest method with a hashes...

2002-05-20 Thread John W. Krahn
Nikola Janceski wrote: > > That would be my grep method > > $pc = grep $testvalue eq $HASH{$_}, keys %HASH; > > any ideas on how to create reverse hash quick? > This returns an odd number of elements: > > my %BYNAME = map { { "$ALL{$_}" => "$_" } } keys %ALL; $ perl -le' %hash = ( PC1 => "Nik

RE: Fastest method with a hashes...

2002-05-20 Thread Nikola Janceski
found it... some damn values were empty. > -Original Message- > From: Nikola Janceski [mailto:[EMAIL PROTECTED]] > Sent: Monday, May 20, 2002 5:17 PM > To: 'Timothy Johnson'; Nikola Janceski; Beginners (E-mail) > Subject: RE: Fastest method with a hashes... >

RE: Fastest method with a hashes...

2002-05-20 Thread Nikola Janceski
imothy Johnson [mailto:[EMAIL PROTECTED]] > Sent: Monday, May 20, 2002 5:08 PM > To: 'Nikola Janceski'; Beginners (E-mail) > Subject: RE: Fastest method with a hashes... > > > > The only other thing I can think of that you haven't mentioned is just > cycling t

RE: Fastest method with a hashes...

2002-05-20 Thread Timothy Johnson
The only other thing I can think of that you haven't mentioned is just cycling through the keys 'till you get one that matches, which is probably not the fastest approach, but if memory is a huge issue, it's probably one of the most efficient. foreach(keys %hash){ if($hash{$_} = $myvalue){