Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Oh my ... shuffle this, splice that ... how's this?
use strict; BEGIN{eval q{use warnings;}} { my %cache; sub Gimme { my( $arr, $n, $clear, $all ) = @_; my @ret = (); $cache{$arr} = {} if defined $clear or not exists $cache{$arr} +; %cache = () if defined $all; while($n){ my $rand = $$arr[rand@$arr]; unless(exists $cache{$arr}{$rand}){ $n--; $cache{$arr}{$rand}++; push @ret, $rand; } if( scalar %{$cache{$arr}} == @$arr ) { warn "No more unique elements left in $arr"; return @ret; } } return @ret; } } my @array = ( 1..10,'a'..'z',keys %:: ); #my($c1, $c2, $c3, $c4, $c5 ) = Gimme(\@array,5); for(1..10){ print "\n\n=head1 $_\n\n"; print "\t$_\n" for Gimme(\@array, 5); } __END__

** The Third rule of perl club is a statement of fact: pod is sexy.

In reply to Re: random elements from array - new twist by PodMaster
in thread random elements from array - new twist by felwick

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others lurking in the Monastery: (1)
    As of 2020-10-24 11:47 GMT
    Find Nodes?
      Voting Booth?
      My favourite web site is:

      Results (243 votes). Check out past polls.