--- Chris Zampese <[EMAIL PROTECTED]> wrote: > When I execute the folowing script (to insert form input into $In), I get an error >message > saying > > unmatched right curly bracket line 60 at end of line > syntax error near "}" Line 60 > > But I have been through the code over and over, and as far as I can see, all the >brackets match > up?? > > Can anyone with a fresh pair of eyes see where I am going wrong?? > > > sub Parse > { > my $buffer; > if($ENV{REQUEST_METHOD}eq'GET') > {$buffer=$ENV{QUERY_STRING};} > else {read(STDIN,$buffer,$ENV{CONTENT_LENGTH});} > my @p = split(/&/,$buffer); > foreach(@p) > { > $_=~tr/+//; > my ($n,$v)=split(/=/,$_,2); > $n=~s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; > $v=~s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; > $v=~s/(\<.*?)(embed|object|script|applet)(.*?\>)/$1$3/gis; > if($In{$n}) {$In{$n}.="\t$v";} > else {$In{$n}=$v;} > } > } > #sub Parse
There are a number of problems with your code snippet, but syntax is not one of them. If it is indented properly to show scope, you can quickly see that the curly brackets are fine: sub Parse { my $buffer; if($ENV{REQUEST_METHOD}eq'GET') { $buffer=$ENV{QUERY_STRING}; } else { read(STDIN,$buffer,$ENV{CONTENT_LENGTH}); } my @p = split(/&/,$buffer); foreach(@p) { $_=~tr/+//; my ($n,$v)=split(/=/,$_,2); $n=~s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; $v=~s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; $v=~s/(\<.*?)(embed|object|script|applet)(.*?\>)/$1$3/gis; if($In{$n}) { $In{$n}.="\t$v"; } else { $In{$n}=$v; } } } Now I'm going to get a bit forthright, so my apologies in advance! That being said, you should never, never try to parse CGI form data by hand. Once you understand thoroughly why you shouldn't, you might be qualified to give it a try. I have a standing deal with everyone to show me there hand-rolled form parsing code and I will find at least 5 bugs or limitations. I've never lost (now Randal or Kevin Meltzer or someone is going to take me up on that :) 1. In your code, you can't easily mix GET and POST (though you rarely want to). 2. You don't test if the read is successful. 3. Does the length of the data read from STDIN match the CONTENT_LENGTH? 4. Does not support the new ';' as a delimeter. 5. $v=~s/(\<.*?)(embed|object|script|applet)(.*?\>)/$1$3/gis; does not belong there. 6. $In{$n}.="\t$v". You should be using a proper data structure. 7. You should be using strict (not everyone does, but code like this tells me the programmer needs it). You can read through http://www.easystreet.com/~ovid/cgi_course/lesson_two/lesson_two.html for a more detailed explanation of the problems here. Again, my apologies if this offends. Cheers, Curtis "Ovid" Poe ===== "Ovid" on http://www.perlmonks.org/ Someone asked me how to count to 10 in Perl: push@A,$_ for reverse q.e...q.n.;for(@A){$_=unpack(q|c|,$_);@a=split//; shift@a;shift@a if $a[$[]eq$[;$_=join q||,@a};print $_,$/for reverse @A __________________________________________________ Do You Yahoo!? Check out Yahoo! Shopping and Yahoo! Auctions for all of your unique holiday gifts! Buy at http://shopping.yahoo.com or bid at http://auctions.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]