" I know there are half a million posts similar to this one but they aren't very helpful in what I'm trying to do..."

Might be a coincidence, but there are half a million [minus a quarter million or two] posts similar to this one that aren't very helpful in terms of conveying exactly what you are trying to do. The code you have posted is really just the synopsis for Algorithm::Numerical::Shuffle, it is not code that demonstrates why you want to remove an element from the randomized array, and then randomize that array again (and presumably continue this in loop until all elements are exhausted). This why, generally speaking, can really effect the number of answers that you will receive.

Since you have no why, i now have to employ the mythical Acme::PSI::ESP and translate your post:

"Hi, i am using Algorithm::Numerical::Shuffle to sort an array. I want to consume elements (like a queue) from this randomized array, but i want to make sure that i only consume unique elements."

If it's really unique elements that you are after, the Perl Cookbook offers a pretty slick snippet in Recipe 4.6. Extracting Unique Elements from a List:
%seen = (); @uniqu = grep { ! $seen{$_} ++ } @list;
So, using that code, we can extract the unique elements before we randomize:
use strict; use warnings; use Algorithm::Numerical::Shuffle qw(shuffle); my @array = (1..10,2..11,3..12); print " begin: @array\n"; my %seen; my @unique = grep {!$seen{$_}++} @array; print " unique: @unique\n"; my @shuffled = shuffle @unique; print "shuffled: @shuffled\n";
While i was writing this post, i thought about encapsulating this 'unique' code into a subroutine. Here are a couple of versions, both callable like:
my @unique = unique(@array);
Version One: (copy-n-paste-n-decorate)
sub unique { my %seen; my @unique = grep {!$seen{$_}++} @_; return @unique; }
Version Two: (make ears bleed)
sub unique { local %_; grep !$_{$_}++, @_ }
Hope this helps, and please elaborate if it doesn't. ;)

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

In reply to (jeffa) Re: removing element from an array by jeffa
in thread removing element from an array by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.