[repost with better subject and code put directly into the message]

Ok, I'm getting closer thanks to the help of all the experts out here!!  I'm 
totally thankful for all of your help.

At http://staff.washington.edu/guru/cards2.cgi when you hit "End Phase" it 
passes, as a hidden form field, the contents of @Draw. (I'm not even
bothering to check any boxes yet.. I need to be sure that no matter what I 
pass the proper @Draw every time).

The first time you hit "End Phase" it's great.  However, subsequent times, 
loses the \r\n at the end of each line and gains two spaces.  This makes it 
so I can't split on the \r\n like I did before hitting "End Phase". How 
should I handle this?  Should I detect whether or not $Draw contains /\n\r/ 
and then split on that, and if not split on /  /?  (and if I should do that, 
how do I do that 8^).

Or, should I make sure that I pass the same thing every time and then not 
have to worry about what the delimiter should be?  (and if I should do it 
that way... uh... how do I to that? ;^)

I hope that makes sense to an expert out there.

Any suggestions on what I should do?

I really am learning though!!  I've finally got my boss to get 'Learning 
Perl 3rd Ed.' and 'Effective Perl Programming'.  Should pick them up 
tomorrow 8^)

-James


#!/usr/local/bin/perl
#include <stdlib.h>

use CGI qw(:standard);
use strict;

print "Content-type: text/html\n\n";

print qq{
<p><a href="cards2.cgi">Start Over</a></p>
};

my @Deck; # The whole deck, orderd
my @Draw;
my $Draw = param("drawHidden") || "";

my @playedCards = param("playedCardsHidden") || "";
my @playedCardsCheckbox = param("playedCardsCheckbox") || "";

my @discardCards = param("discardCardsHidden") || "";
my @discardCardsCheckbox = param("discardCardsCheckbox") || "";

my $iterate;
my $random;
my $control;
my $counter = 0;
my $valueName;
my $turnCounter = param("turnCounter") || 0;

# if the update button has NOT been pressed.
# e.g. when the page is just run for the first time.

if (param("update") eq "no" || param("update") eq undef){

open (DECK,"deck.txt");
@Deck = <DECK>;
close DECK;

@Draw = @Deck;

&Randomize (\@Draw);

sub Randomize
{
  $random = shift;
  for ($iterate = @$random; --$iterate; )
   {
    $control = int rand ($iterate + 1);
    if ($iterate == $control)
     { next; }
    @$random[$iterate, $control] = @$random[$control, $iterate];
   }
}


# Run this code whenever the "End turn" button is pressed

}else{

#######################################
#  This works great the first time    #
#    but fails the rest of the time   #
#    because it loses it's \r\n       #
#######################################

@Draw = split(/\r\n/ ,$Draw);


print "Start Printing \@Draw <br>";

print @Draw;


print "<br> End Printing  \@Draw";
print "<br><br>\@Draw has ", my $number_of_elements = @Draw, " elements";

$turnCounter += 1;

# Perform all the actions related to
# @inPlay



# Perform all the actions related to
# @inDiscard



# Perform all the actions realted to
# @Draw



# end of the "update" if/else loop
}


###################################
# Now we start the output section #
###################################

print qq|
<html>
<body bgcolor="#ffffff">


  <form name="form" method="post" action="cards2.cgi">
  <input type="hidden" name="update" value="yes">
  <input type="submit" value="End Phase">

<div style="font-size:2em;">Draw Deck</div>

<table border="1" align="left">
<tr>
<th>#</th>
<th>Card Name</th>
<th>Play</th>
<th>Discard</th>
</tr>
|;
#This prints out the randomized array





foreach my $item (@Draw){

my @foo = split(/\|/, $item);


$valueName = $foo[1];

print "<tr>\n";
     print "\t<td>$counter</td>\n";

     print "\t<td>$valueName</td>\n";

     print "\t<td><input type='checkbox' name='playedCardsCheckbox' 
value=''></td>\n";

     print "\t<td><input type='checkbox' name='discardCardsCheckbox' 
value=''></td>\n";

print "</tr>\n";


$counter++;
}


print "</table>\n";

print qq{
<table border="1">
<tr>
  <th>In Play</th>
  <th>In Discard</th>
</tr>

<tr>
   <td>Cards in play are listed here</td>
   <td>Cards in the discard pile are listed here</td>
</tr>

</table>

};



print qq{

####################################
# here's where I'm passing @Draw   #
####################################

  <input type="hidden" name="drawHidden" value="@Draw">

</form>
</body>
</html>

}



_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: 
http://photos.msn.com/support/worldwide.aspx


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to