454,278 Members | 1,566 Online
Need help? Post your question and get tips & solutions from a community of 454,278 IT Pros & Developers. It's quick & easy.

# Data Manipulation with pop, push, and shift.

 P: 2 My instructor has asked me to use the pop, shift, and push functions to write a script that sufficiently "shuffles" a simulated deck of cards before printing the top five cards. I came up with the following code but the problem I am having is that I can't seem to shuffle by just using pop, push, and shift. I think the problem for me is trying to understand what constitutes a shuffle because there are many different ways to shuffle a deck of cards. I also am aware there is a shuffle function but we are not allowed to use this for the exercise. So if I had a better understanding of how the algorithm worked I might get a little further than where I am at. Expand|Select|Wrap|Line Numbers #!/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"); push(@startingdeck, shift(@startingdeck)); push(@startingdeck, pop(@startingdeck)); foreach my \$card (@startingdeck) { print "Card: \$card\n"} Mar 28 '08 #1