Shuffling 'cards' using perl.

I would be very grateful if someone could help me with this; using pop, shift, push, and the starting code below, I'd like a script that sufficiently "shuffles" a simulated deck of cards before printing the top five cards.

#!/usr/bin/perl

@startingdeck = ("A H","2 H","3 H","4 H","5 H","6 H","7 H","8 H",
                 "9 H","10 H","J H","Q H","K H",
                 "A D","2 D","3 D","4 D","5 D","6 D","7 D","8 D",
                 "9 D","10 D","J D","Q D","K D",
                 "A C","2 C","3 C","4 C","5 C","6 C","7 C","8 C",
                 "9 C","10 C","J C","Q C","K C",
                 "A S","2 S","3 S","4 S","5 S","6 S","7 S","8 S",
                 "9 S","10 S","J S","Q S","K S");

When posting the question, post the expected output as well.

I did post it, I explained what I expect to come out of it, first it shuffles the 'cards' and prints out the top 5 'cards', which are different each time [Randomizer].

$
$ cat shuffle.pl
#!/usr/bin/perl
$n = defined $ARGV[0] ? $ARGV[0] : 1;
@startingdeck = ("A H","2 H","3 H","4 H","5 H","6 H","7 H","8 H",
                 "9 H","10 H","J H","Q H","K H",
                 "A D","2 D","3 D","4 D","5 D","6 D","7 D","8 D",
                 "9 D","10 D","J D","Q D","K D",
                 "A C","2 C","3 C","4 C","5 C","6 C","7 C","8 C",
                 "9 C","10 C","J C","Q C","K C",
                 "A S","2 S","3 S","4 S","5 S","6 S","7 S","8 S",
                 "9 S","10 S","J S","Q S","K S");
foreach $j (1..$n) {
  print "Top 5 cards for shuffle # $j\n";
  shuffle();
}
sub shuffle {
  foreach $i (1..5){
    printf("%d => %s\n",$i,$startingdeck[sprintf("%d",rand(51))]);
  }
}
$
$ perl shuffle.pl
Top 5 cards for shuffle # 1
1 => 8 C
2 => 8 D
3 => 9 D
4 => 4 S
5 => 7 D
$
$ perl shuffle.pl 3
Top 5 cards for shuffle # 1
1 => K H
2 => 2 H
3 => A H
4 => A S
5 => A D
Top 5 cards for shuffle # 2
1 => 3 C
2 => 7 D
3 => J D
4 => J H
5 => 7 S
Top 5 cards for shuffle # 3
1 => 7 S
2 => K H
3 => 3 S
4 => 10 H
5 => J H
$
$

tyler_durden

Cool, thxz tyler, but as I mentioned at the start before the code,that I am looking for a script that does the shuffling using these 3 commands:pop, shift, & push.

Thxz for the hard wokr~

Yes but why ?
What do pop, shift and push have to do with shuffling a list ?
Where and how do they fit in the picture ?

It's like you want to fly a Cessna over the Mississippi and you are asking for Chinese Tangrams.

tyler_durden

Sounds like a homework assignment. Only the education system would be that sadistic to ask you to do something silly like ignore modules and write something completely clunky and complicated.

Yep, it's an homework assignment...>_> And doing this way is annoying...

---------- Post updated 08-20-09 at 04:08 AM ---------- Previous update was 08-19-09 at 03:10 PM ----------

So, could anyone help me out?

It is homework, he mentions that on one of the other perl forums where he is posting the same questions.

Edit: I see he now mentions it is homework

Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

Thank You.

The UNIX and Linux Forums.