ZiaTioN has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Blackjack.pl/cgi
by hawtin (Prior) on Feb 02, 2003 at 10:38 UTC

    One obvious improvement would be to actually simulate the deck of cards. As your program stands you can deal a hand with five 2s

    I would suggest using a closure to hold a pack

    # Limit the region where the variable @pack is visible { my(@pack); sub new_pack { my(@sorted_pack); foreach my $suit ("S","H","D","C") { foreach $val (0..10,"J","Q","K","A") { push(@sorted_pack,$val.$suit); } } # This way of shuffling a pack is untested, # inefficient and probably flawed @pack = (); while($#sorted_pack > 0) { my($idx); $idx = rand $#sorted_pack; push(@pack,splice(@sorted_pack,$idx,1)); } } sub next_card { new_pack() if(!@pack); return pop(@pack); } } # NB: None of this code is tested
      Good idea. Adding suites was something I was going to do after I got it working on my web page. And now I have some decent code to go off of. Thanx...
Re: Blackjack.pl/cgi
by Pardus (Pilgrim) on Feb 02, 2003 at 10:29 UTC
    Maybe if you tell us about the problems, instead of just pasting in the code ....
    --
    Jaap Karssenberg || Pardus (Larus)? <pardus@cpan.org>
    >>>> Zoidberg: So many memories, so many strange fluids gushing out of patients' bodies.... <<<<
      well the problem is I get a server error when I try to load the page. As you can probably tell from my post and the code alone that this is not a command line script. All I get is an Internal Server Error.
        hmmm - no syntax errors, and if I run it commandline it outputs html.
        If I run it in my appache it works ... well I get told I lose all the time :s

        • Are you really sure the web server configuration is in working order ?
          • Web server understands perl ?
          • Web server has appropriate permissions ?
          • Server has uptodate modules installed ?
        • Did you check the error log for detailed die messages etc. ?
        • Is cgi enabled for the directory where the script is ?
        1) CGI.pm can also be invoked with commandline args instead of

        There really should be a CGI/webserver check-list on perlmonks
        --
        Jaap Karssenberg || Pardus (Larus)? <pardus@cpan.org>
        >>>> Zoidberg: So many memories, so many strange fluids gushing out of patients' bodies.... <<<<