On 9/3/08 4:01 PM, "Raul Ruiz Jr." <[EMAIL PROTECTED]> wrote:
> I created a card shuffling program and it works
> fine. However, for my project I am to place the shuffling part of my
> code in a separate script as a subroutine.
>
> I am to remove the code
> that does the shuffling and include it as another function in
> obj13-lib.pl. So I did this and after the first "hand" is dealt, call the
> shuffling function again before dealing another, different hand.
>
>
>
>
> I call it obj-lib.pl and my main script obj13.pl.
>
> I
> did put it together but my obj13.pl script is not shuffling my cards
> and I need to print out two sets of five elements. And I was not able
> to get it to print out 2 sets of five elements.
>
> Where am I going wrong? Looking for some help and a point in the right
> direction. Thanks everyone.
>
> Below is my code:
> obj13.pl
>
> #!/usr/bin/perl
>
> require 'obj13-lib.pl';
>
> my @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");
>
>
> print "the top five cards are @startingdeck[0..4]\n";
>
> #_END_
> _________________________________________________________________________
> My library script code here for my shuffle program:
>
> obj13-lib.pl
>
> #!/usr/bin/perl
>
> sub shuffle(){
>
> my @right;
> my
> @left;
> SHUFFLE:
> unshift @left, pop @startingdeck for 1..26;
> @right = @startingdeck;
> @startingdeck = ();
> while(@left or @right){
> if (rand() < 0.5){
> @left and push @startingdeck, shift @left
> }else{
> @right and push @startingdeck, shift @right
> }
> };
>
> rand() < 0.9 and goto SHUFFLE;
> }
>
> 1;
>
> #_END_
>
>
I do not see you calling the procedure anywhere.
And when you call it, you need to pass your array as a parameter to the
sub-routine.