in reply to Re: Add a fixed number of unique elements to hash
in thread Add a fixed number of unique elements to hash

If shuffle takes too long you could do this:

sub uploadPlaylist { for my $i ( 1 .. $numOfRandFiles ) { $playList{ splice @audioFiles, int rand @audioFiles, 1 } = $i; } }
Naked blocks are fun! -- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
Re^3: Add a fixed number of unique elements to hash
by Vasek (Acolyte) on Mar 05, 2023 at 22:55 UTC
    Thx a lot jwkrahn! Splice is the key for me. Other solutions that use "factory" modules are out of the question, i.e. this machine is running perl 5.004, which has quite a few syntactical differences compared to today's perl versions. Of course, I could try transplanting the modules, but my only connection to this old SGI machine is via nfs sharing over a software half-speed network interface (since it can no longer be communicated with securely with today's settings).