Re: mysterious leading spaces

2002-03-13 Thread James Woods

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

2002-03-13 Thread Tagore Smith

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

2002-03-13 Thread fliptop

James Woods wrote:

> 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.


if your passing all the data in one , retrieving it with

@Data = $cgi->param('drawHidden');

will give @Data just one element, which should contain all the data. 
you'll have to parse it again to get each line into an array.  maybe 
something like this would be better:

@Data = split "\n", $cgi->param('drawHidden');


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




RE: mysterious leading spaces

2002-03-13 Thread James Woods

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 "\n";
 print "\t$counter\n";

 print qq{\t$foo[1]\n};

 print "\t\n";

 print "\t\n";

print "\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 "";
foreach (@Draw){
chomp;
print $_;
}
print "";

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

2002-03-12 Thread Tagore Smith

James Woods wrote:
>
> The code I was referring to was:
>
> foreach (@Draw) {
> s/\s+$//g; # remove all whitespace at the end of a row
> print "\n";
> }
>

   Are you reading the data into an array in the script and then printing
the array using interpolation inside double quotes?

   print @Array; and print "@Array";. are different. The second will
separate the items with spaces.

Tagore Smith




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




Re: mysterious leading spaces (sample text included)

2002-03-12 Thread fliptop

James Woods wrote:

> Putting that code in place of the chomp code that was suggested earlier 
> produced the same result.


i just tried this test case:

# one with blank spaces, two with a tab,
# three with a \n, four with several \n's
my @Data = ('one   ', 'two  ', 'three
', 'four


');

foreach (@Data) {
   s/\s+$//g;
   print "\n";
}

and the output was:






so i don't know how i can help any more.  it should work as expected.


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




Re: mysterious leading spaces (sample text included)

2002-03-12 Thread James Woods

fliptop wrote:

according to a 'view source' on the above url, your hidden input params
do indeed have a new line on the end.

try this (instead of chomp):

foreach (@Draw) {
s/\s+$//g;  # remove all whitespace at the end of a row
print "\n";
}

James wrote:

Putting that code in place of the chomp code that was suggested earlier 
produced the same result.

>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.

fliptop wrote:

i'm not sure which code you are referring to.

Jams wrote:

The code I was referring to was:

foreach (@Draw) {
s/\s+$//g;  # remove all whitespace at the end of a row
print "\n";
}

Thanks so much for spending so much time on this.  When I decided that this 
sounded like a "simple" project to help me learn Perl, I obvously had no 
idea what I was getting myself into.

Any more ideas?

-James

_
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 (sample text included)

2002-03-12 Thread fliptop

James Woods wrote:

> 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.


according to a 'view source' on the above url, your hidden input params 
do indeed have a new line on the end.

try this (instead of chomp):

foreach (@Draw) {
s/\s+$//g;  # remove all whitespace at the end of a row
print "\n";
}

> 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.


i'm not sure which code you are referring to.


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




Re: mysterious leading spaces (sample text included)

2002-03-12 Thread James Woods

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 "\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 "\n";
}


or like this:


map {
   chomp;
   print "\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]




Re: mysterious leading spaces (same foreach problem w/ more details)

2002-03-12 Thread Joshua Hayden

- 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 "\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 "\n";
}

Best Regards,
JOSHUA D. HAYDEN




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




Re: mysterious leading spaces (same foreach problem w/ more details)

2002-03-11 Thread fliptop

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 "\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 "\n";
}


or like this:


map {
   chomp;
   print "\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]




Re: mysterious leading spaces (same foreach problem w/ more details)

2002-03-11 Thread James Woods

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 "\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

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: Mon, 11 Mar 2002 19:41:45 -0500

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:



why not pass it like this (in your html):




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]






James Woods
Web Developer for Christ by night
WebMaster at http://www.tacoma.washington.edu by day
Web Applications and Cold Fusion Programming
[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)

2002-03-11 Thread fliptop

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:



why not pass it like this (in your html):




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]