in reply to Allocation of anonymous arrays

Any ideas?

An explanation of what problem you're trying to solve would be helpful

At first look (at this late hour), the way that hash is populated/used look kinda silly and poinless :)

Perl will hapilly reuse reference addresses ... since the hash keys are strings, as soon the references are gone, their refaddr's are free for reuse by perl

If you want unique keys you're better off using a UUID or some such like Session::Token - Portable, secure, efficient, simple random session token generation that satisfies those OWASP recommendations

  • Comment on Re: Allocation of anonymous arrays (ref addr)

Replies are listed 'Best First'.
Re^2: Allocation of anonymous arrays (ref addr repeats)
by Anonymous Monk on Feb 07, 2014 at 09:53 UTC
    fw() for 1 .. 10; sub fw { my %uniq; for my $ix ( 0 .. 100 ){ for my $key ( wf() ){ my $count = $uniq{$key}++; if( $count > 1 ){ my $keycount = keys %uniq; my $buckets = %uniq; print "started repeating at iteration $ix after only $ +keycount in $buckets buckets \n"; return; } } } } sub wf { my %f; $f{ [] } = [0]; $f{ [] } = [1]; $f{ [] } = [2]; $f{ [] } = [3]; return keys %f; } __END__ started repeating at iteration 8 after only 26 in 20/32 buckets started repeating at iteration 4 after only 14 in 13/32 buckets started repeating at iteration 5 after only 17 in 14/32 buckets started repeating at iteration 5 after only 17 in 13/32 buckets started repeating at iteration 5 after only 19 in 15/32 buckets started repeating at iteration 5 after only 18 in 16/32 buckets started repeating at iteration 6 after only 18 in 16/32 buckets started repeating at iteration 7 after only 20 in 15/32 buckets started repeating at iteration 6 after only 18 in 14/32 buckets started repeating at iteration 7 after only 26 in 21/32 buckets
      sorry for my ignorance Anonymous, but what are you demonstrating here? can you explain your code?

      There are no rules, there are no thumbs..
      Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

        sorry for my ignorance Anonymous, but what are you demonstrating here? can you explain your code?

        Um, what do you think I'm demonstrating? What do you understand about the code?

        :)

        I think I'm demonstrating that reference adresses get reused rather quickly ...

        Is this relevant for the OP? I can't say :|

        If all that happens is  my %f = ([],[]); my %g = reverse %f; then both %f and %g will have unique key-value pairs guaranteed

        If at some point other references are added as keys then collisions will happen