RE: mysterious leading spaces
First off, thanks for helping me, I really appreciate it. I'm printing out the @Draw using this code: foreach my $item (@Draw){ my @foo = split(/\|/, $item); my $rowColor; if ($counter == 7){ $rowColor = #c0c0c0; }else{ $rowColor = #ff; } print tr bgcolor='$rowColor'\n; print \ttd$counter/td\n; print qq{\ttda href=$foo[3] target=_new$foo[1]/a/td\n}; print \ttdinput type='checkbox' name='PlayedCheckbox' value='$counter'/td\n; print \ttdinput type='checkbox' name='discardCardsCheckbox' value=''/td\n; print /tr\n; $counter++; } The above code works great when the @Draw is populated from my text file (which happens pre-submission). However, when the form is submitted, I only get the first record of @Draw. This code below is what I'm using to populate the textarea which passes 'drawHidden' (which is what populates the @Draw post-submission). Note that if you erase a line or two from the textarea, that is correctly reflected upon submission. However, I'm still just managing to write out the very first record of @Draw, and not all of the records. Does that make any sense? print textarea rows='10' cols='80' name='drawHidden'; foreach (@Draw){ chomp; print $_; } print /textarea; So I guess my newest question is, what am I doing wrong to only print out the first record of @Draw? This is where you can see my mess in action 8^) http://staff.washington.edu/guru/james.cgi _ Send and receive Hotmail on your mobile device: http://mobile.msn.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: mysterious leading spaces
James Woods wrote: So I guess my newest question is, what am I doing wrong to only print out the first record of @Draw? It's hard to know for sure without seeing the code where you initialize @Draw. I went back and looked at earlier posts, and your initial problem (the leading spaces) was because you were printing the array in double-quoted context. In terms of getting only the first element, you're using a succession of hidden inputs with the same name, right? Are you calling $cgi-param in list context? If you call it in scalar context you'll only get one value back. So you would do it like this: @Draw=$cgiobject-param('hiddendata'); but not: $Draw=$cgiobject-param('hiddendata'); or $Draw[0]=$cgiobject-param('hiddendata'); or @Draw[0]=$cgiobject-param('hiddendata'); Anyway, without seing the code where @Draw is initialized it's hard to know, but if you are doing one of the above, that's the problem. Hope that helps. Tagore Smith -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: mysterious leading spaces
My problem was that I wasn't splitting my posted form data on the \n into my @Draw. And Tagore, yes, I was (at least at one time) calling it in scalar context. Thank you Tagore and Fliptop (and everyone else who helped). I hope this helps some other newbie sometime! I appreciate you putting up with me for so many posts 8^) However, I'm sure that this will not be my last post 8^) heh heh heh... Bless both of you. -James Original Message Follows From: Tagore Smith [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: Re: mysterious leading spaces Date: Wed, 13 Mar 2002 14:13:38 -0500 James Woods wrote: So I guess my newest question is, what am I doing wrong to only print out the first record of @Draw? It's hard to know for sure without seeing the code where you initialize @Draw. I went back and looked at earlier posts, and your initial problem (the leading spaces) was because you were printing the array in double-quoted context. In terms of getting only the first element, you're using a succession of hidden inputs with the same name, right? Are you calling $cgi-param in list context? If you call it in scalar context you'll only get one value back. So you would do it like this: @Draw=$cgiobject-param('hiddendata'); but not: $Draw=$cgiobject-param('hiddendata'); or $Draw[0]=$cgiobject-param('hiddendata'); or @Draw[0]=$cgiobject-param('hiddendata'); Anyway, without seing the code where @Draw is initialized it's hard to know, but if you are doing one of the above, that's the problem. Hope that helps. Tagore Smith -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] _ Chat with friends online, try MSN Messenger: http://messenger.msn.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: mysterious leading spaces (same foreach problem w/ more details)
- Original Message - From: James Woods [EMAIL PROTECTED] To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Monday, March 11, 2002 10:56 PM Subject: Re: mysterious leading spaces (same foreach problem w/ more details) I used the following code to write out all my hidden fields. It didn't get rid of the newline or caridge return characters at the end though. foreach my $item (@Draw){ my $counter = 0; my $daValue = $item; chomp($daValue); print input type='hidden' name='drawHidden' value='$daValue'\n; $counter++; } I accessed and created the array with this code: my @Draw = $cgi-param(drawHidden) || ; Any ideas why I can't get rid of the ending characters? (besides the fact that I really have no idea what I'm doing? 8^) -James I had the same problem in a script I was writing. You could use this to get rid of your caridge returns. foreach (@Draw) { chomp; s/\n//; print input type='hidden' name='drawHidden' value='$_'\n; } Best Regards, JOSHUA D. HAYDEN -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: mysterious leading spaces (sample text included)
Here is the raw text from my text file (the original source). It's created on a Windows machine (??in case that makes a difference with linefeeds vs. carridge returns??) then put on an apache web server. f|Gimlis Axe|p|fellowship/large/14gimlisbattleaxe.html f|Hand Axe|p|minesofmoria/large/010handaxe.html f|Gimlis Helm|p|fellowship/large/15gimlishelm.html f|Dwarven Armor|p|fellowship/large/8dwarvenarmor.html f|Dwarven Bracer|p|minesofmoria/large/003dwarvenbracers.html f|Gandalfs Staff|p|minesofmoria/large/022gandalfsstaff.html f|Glamdring|p|fellowship/large/75glamdring.html f|Sleep Cahadras|d|fellowship/large/84sleepcaradhras.html f|Axe Strike|d|fellowship/large/3axestrike.html on http://staff.washington.edu/guru/james.cgi you should be able to see the progression of the @Draw array in the large textareas. Here's something that I need some education on: why is it when I just put the @Draw array into a hidden field, does it pass all the data, and when I use the code suggested, it only passes the first record? It seems to me from what I've read about CGI.pm that it would take all the hidden fields and put them into the @Draw array like I've specified. Oh well. Thanks all for your help so far! It's been educational Original Message Follows From: fliptop [EMAIL PROTECTED] Reply-To: [EMAIL PROTECTED] To: James Woods [EMAIL PROTECTED] CC: [EMAIL PROTECTED] Subject: Re: mysterious leading spaces (same foreach problem w/ more details) Date: Tue, 12 Mar 2002 00:19:50 -0500 James Woods wrote: I used the following code to write out all my hidden fields. It didn't get rid of the newline or caridge return characters at the end though. foreach my $item (@Draw){ my $counter = 0; my $daValue = $item; chomp($daValue); print input type='hidden' name='drawHidden' value='$daValue'\n; $counter++; } I accessed and created the array with this code: my @Draw = $cgi-param(drawHidden) || ; Any ideas why I can't get rid of the ending characters? (besides the fact that I really have no idea what I'm doing? 8^) well i don't know offhand - i'd have to examine what's in @Draw. i'd suspect you may have more in there than chomp() can handle. can you post an example portion of @Draw that displays the strange behavior? btw, your loop can be rewritten as such: foreach (@Draw) { chomp; print input type='hidden' name='drawHidden' value='$_'\n; } or like this: map { chomp; print input type='hidden' name='drawHidden' value='$_'\n; } @Draw; without all that $item/$counter stuff. i don't understand what the $counter is for anyway since you're setting it to 0 on each loop iteration. _ Chat with friends online, try MSN Messenger: http://messenger.msn.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
mysterious leading spaces (same foreach problem w/ more details)
OK, I've got a form where I'm passing an array via a hidden form field. The problem is that (after submission) I'm getting a leading space at the beginning of each 'record' after the first. In other words, the first 'record' is being passed as it should be, but each other record is being prepended with a space. That leading space is causing me headaches. when trying to do a foreach on the array, after submitting the form. How do I either 1) Ditch the prepended space, or 2) prevent the space from ever appearing? The site is http://staff.washington.edu/guru/james.cgi #This is the hidden field print input type='hidden' name='drawHidden' value='@Draw'; #This is the foreach foreach my $item (@Draw){ my @foo = split(/\|/, $item); my $rowColor; if ($counter == 7){ $rowColor = #c0c0c0; }else{ $rowColor = #ff; } $valueName = $foo[1]; print tr bgcolor='$rowColor'\n; print \ttd$counter/td\n; print qq{\ttda href=$foo[3] target=_new$valueName/a/td\n}; print \ttdinput type='checkbox' name='PlayedCheckbox' value='$counter'/td\n; print \ttdinput type='checkbox' name='discardCardsCheckbox' value=''/td\n; print /tr\n; $counter++; } _ 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]
Re: mysterious leading spaces (same foreach problem w/ more details)
James Woods wrote: That leading space is causing me headaches. when trying to do a foreach on the array, after submitting the form. instead of packing a huge array into one form var like this: input type='hidden' name='drawHidden' value='@Draw' why not pass it like this (in your html): input type=hidden name=drawHidden value=$Draw[0] input type=hidden name=drawHidden value=$Draw[1] etc... then you can process it as such: @drawHidden = $cgi-param('drawHidden'); -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: mysterious leading spaces (same foreach problem w/ more details)
James Woods wrote: I used the following code to write out all my hidden fields. It didn't get rid of the newline or caridge return characters at the end though. foreach my $item (@Draw){ my $counter = 0; my $daValue = $item; chomp($daValue); print input type='hidden' name='drawHidden' value='$daValue'\n; $counter++; } I accessed and created the array with this code: my @Draw = $cgi-param(drawHidden) || ; Any ideas why I can't get rid of the ending characters? (besides the fact that I really have no idea what I'm doing? 8^) well i don't know offhand - i'd have to examine what's in @Draw. i'd suspect you may have more in there than chomp() can handle. can you post an example portion of @Draw that displays the strange behavior? btw, your loop can be rewritten as such: foreach (@Draw) { chomp; print input type='hidden' name='drawHidden' value='$_'\n; } or like this: map { chomp; print input type='hidden' name='drawHidden' value='$_'\n; } @Draw; without all that $item/$counter stuff. i don't understand what the $counter is for anyway since you're setting it to 0 on each loop iteration. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]