Hey guys thanks for your help, after many hours of toil, I seem to have worked it out. I did all this BEFORE reading Marshall's reply. Feeling quite happy with myself for finally getting it to work :). Could I have some opinions on the way I went about it? Should I have done anything differently/more efficiently?

#!/usr/bin/perl -w OUTER: @suit=('spades', 'hearts', 'clubs', 'diamonds'); foreach $suit(@suit) { INNER: @types=( "ace","2","3","4","5","6","7","8","9","10","jack"," +queen","king"); foreach $types(@types) { $card="$types of $suit"; print "$card\n"; $cardcounter++; push(@cards,$card,); } } print "\n"x2; print "$cardcounter cards have been created\n"; print "\n"x2; ATTEMPT: for ($counter=1;$counter<11;) { $i = int(rand(@cards)) ; push (@alreadyused,@cards[$i]); $count=grep (/@cards[$i]/i,@alreadyused); if ($count<2) { print "Random card is: @cards[$i]\n"; $counter++; push (@iterations,@cards[$i]); } else {next ATTEMPT;} } print "\n"x2; $number=@iterations; print "$number random cards have been chosen, with no duplicates";

In reply to Re: Nested foreach loops by peterstriker
in thread Nested foreach loops by peterstriker

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.