Hi,

Trey Harris wrote:
> In a message dated Mon, 4 Apr 2005, Ingo Blechschmidt writes:
>> What does pick return on hashes? Does it return a random value or a
>> random pair? (I suppose returning a pair is more useful.)
> 
> I'd assume in all cases that pick returns an *alias*, and in the case
> of hashes, an alias to the pair:
> 
>   # Add entropy to your hash
>   for 1..$entropy_thresshold {
>       %hash.pick.value *= rand $scribble_factor;
>   }

I like that, too. So:
  my @array = <a b c d>;
  my $elem  = @array.pick;
  $elem     = "z"; # $elem now "z", @array unchanged

  my @array = <a b c d>;
  my $elem := @array.pick;
  $elem     = "z"; # $elem now "z", @array changed
                   # (any(@array) eq "z" now true)

Same for hashes:
  my %hash = (a => 1, b => 2);
  my $pair = %hash.pick;
  $pair = ...; # %hash unchanged

  my %hash = (a => 1, b => 2),
  my $pair := %hash.pick;
  $pair = ...; # %hash changed


--Ingo

-- 
Linux, the choice of a GNU | Black holes result when God divides the
generation on a dual AMD   | universe by zero.  
Athlon!                    | 

Reply via email to