----- Original Message ---- From: Michael Mathews <[EMAIL PROTECTED]>
On 30/05/06, Ovid <[EMAIL PROTECTED]> wrote: > > I assume this is just an attempt to learn Perl6 and not to write a serious > > CGI parser? > > Assuming it's the former and not the latter, I don't really have much to > > comment on, > > though there are a few things I would change. > > How mysterious. Short of begging, what would it take to get you to > reveal the "few things you would change"? Do I need to pony up another > 1000 Pesos (which will not actually be honoured)? Now that I read what I wrote, I guess that might have sounded a bit annoying for me to mention that I would change things but then not mention what I would change. Much of the changes would be stylistic in nature, but not all (I'm running this against Pugs and assuming it's correct). Here's my take on it: #!/usr/bin/pugs print "content-type: text/html\n\n"; my %q; for %ENV<QUERY_STRING>.split('&') -> $nv { my ($n, $v) = $nv.split('='); decode($n); decode($v); %q{$n} = [] unless %q.exists($n); # %q{$n} //= []; # first try, but I don't think it's correct %q{$n}.push($v); } for %q.kv -> $key, $value { say "$key => $value.join(', ') <br>"; } sub decode($input is rw) { $input ~~ s:Perl5:g/\+/ /; $input ~~ s:Perl5:g/%(..)/{chr(:16["0x$0"])}/; } This ignores the ";" query string separator, POST parameters and a number of other things, but since this isn't an attempt to get CGI correct but instead is an attempt to better understand Perl6, that's OK. Whether or not my code is a significant improvement over your's remains to be seen :) I also tried to do this: my ($n, $v) = $nv.split('=').map(decode($_)); That and a number of other variants all failed miserably with errors similar to: Can't modify constant item: VStr ... Cheers, Ovid