On Wed, 2008-09-03 at 12:51 -0700, Raul Ruiz Jr. 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");

# 'my' makes the variable lexically-scoped to the file.
#  Use 'our' instead:
our @startingdeck = ...

> 
> 
> print "the top five cards are @startingdeck[0..4]\n";

# Call your subroutine before the print.

> 
> #_END_ 
> _________________________________________________________________________
> My second library script code here is called on to complete 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_

 
-- 
Just my 0.00000002 million dollars worth,
  Shawn

"Where there's duct tape, there's hope."
        Cross Time Cafe

"Perl is the duct tape of the Internet."
        Hassan Schroeder, Sun's first webmaster


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to