Re: CGI on 6
On Mon, May 29, 2006 at 05:28:53PM -0700, Ovid wrote: 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 ... Many thanks to Joel and ovid, your suggestions are extremely enlightening. The Can't modify constant item: VStr... is showing up because my decode sub is trying to modify it's argument in-place (not a copy of the argument). Adding the is copy phrase allows it to work as expected. hmm... I like that. Joel's point about auto-vivification is good, It's not a bug, it's a feature, dammit. I'm gonna use it. Strangely %q$n.push($v); doesn't work, but %q.{$n}.push($v); does. What's the difference? #!/usr/bin/pugs my %q = (); for %ENVQUERY_STRING.split('') - $nv { my ($n, $v) = $nv.split('=').map: decode; %q.{$n}.push($v); # auto-vivify!! } print content-type: text/html\n\n; for (%q.keys) { say $_ = ~%q.{$_}.join(', ')~'br' } sub decode(my $input is copy) { $input ~~ s:Perl5:g/\+/ /; $input ~~ s:Perl5:g/%(..)/{chr(:16($0))}/; return $input; }
Re: CGI on 6
On Tue, May 30, 2006 at 07:56:40AM +0100, Michael Mathews wrote: : Strangely %q$n.push($v); doesn't : work, but %q.{$n}.push($v); does. What's the difference? The first is equivalent to %q{'$n'}.push($v). Larry
Re: CGI on 6
Michael Mathews skribis 2006-05-30 0:48 (+0100): Yes, this is a learning exercise (you may provide links to the real pugs CGI solution -- it's not easy to find) but any advice you give could possibly be a learning experience for more than just me. I recommend that you read his CGI course. It's very insightful, and gives quite a few pointers to things that often go wrong when people invent their own wheels. The URL is in his signature. Juerd -- http://convolution.nl/maak_juerd_blij.html http://convolution.nl/make_juerd_happy.html http://convolution.nl/gajigu_juerd_n.html
Re: CGI on 6
On 30/05/06, Larry Wall [EMAIL PROTECTED] wrote: On Tue, May 30, 2006 at 07:56:40AM +0100, Michael Mathews wrote: : Strangely %q$n.push($v); doesn't : work, but %q.{$n}.push($v); does. What's the difference? The first is equivalent to %q{'$n'}.push($v). I see now that those pointy braces take their contents literally, so literally a key whith the characters dollar, en. Not what I meant at all! Thanks for the help. --michael
Re: CGI on 6
On 5/30/06, Michael Mathews [EMAIL PROTECTED] wrote: I see now that those pointy braces take their contents literally, so literally a key whith the characters dollar, en. Not what I meant at all! Thanks for the help. The construct you're looking for is %q«$n» which may also be written %q$n if you can't type the first kind. The double-angles permit interpolation, by analogy to double quotes. Stuart
Re: CGI on 6
On 5/30/06, Stuart Cook [EMAIL PROTECTED] wrote: The construct you're looking for is (although in this case %q{$n} is probably more appropriate)
Re: CGI on 6
(would that be a pliki? a sixwiki? a plixi? erm-) psiki, where the p is silent. Like what you throw when you fancy a free day off work. -- Humpty Dumpty sat on the wall, Humpty Dumpty had a great fall, All the King's horses and all the King's men | http://surreal.istic.org/ Couldn't put Humpty together again. | powered by cat and ^d Perhaps they shouldn't have given the horses the first go. pgpJCW4WLd6sq.pgp Description: PGP signature
Re: CGI on 6
On 28/05/06, Juerd [EMAIL PROTECTED] wrote: The exegeses are not updated to follow the current specifications. They're still useful, so they're kept around, but the syntax is out of date. Synopses are kept up to date. See http://dev.perl.org/perl6/doc/design/syn/S05.html Ah! I see. Thank you. This is extremely important information. I'd like to see it in large red letters across the top of the exegesis page, for example. And, as an incentive, I'm offering 1000 Colombian Pesos to the first person to author a working example of s/+/ /g; in Perl 6*. $foo ~~ s:Perl5:g/\+/ /; ¡Aye Carumba! That works! Your cheque is in the email. I swear. :-) --michael
Re: CGI on 6
Whack number two. I *think* I've implemented URI decoding, with Juerd's help. I don't know how my hackish code will manage with various flavours of UTF (especially wide characters) but I'll leave that until it proves to be a problem. This works with my install of pugs. I still have some TODOs, if anyone wants to have a go... #!/usr/bin/pugs print content-type: text/html\n\n; my %q = (); my @q = split '', %ENV.{'QUERY_STRING'}; for (@q) { my ($n, $v) = split '=', $_; #TODO: handle multiple values and same key %q.{decode($n)} = decode($v); } for (%q.keys) { say $_, = , %q.{$_}, br; } sub decode($input is rw) { #TODO: handle wide characters? $input ~~ s:Perl5:g/\+/ /; $input ~~ s:Perl5:g/%(..)/{chr(:16[0x$0])}/; return $input; } --michael
Re: CGI on 6
On Mon, May 29, 2006 at 09:14:43AM +0100, Michael Mathews wrote: : On 28/05/06, Juerd [EMAIL PROTECTED] wrote: : The exegeses are not updated to follow the current specifications. : They're still useful, so they're kept around, but the syntax is out of : date. : Synopses are kept up to date. See : http://dev.perl.org/perl6/doc/design/syn/S05.html : : Ah! I see. Thank you. This is extremely important information. I'd : like to see it in large red letters across the top of the exegesis : page, for example. Done, hopefully will propagate to dev.perl.org within 6 hrs. Larry
Re: CGI on 6
Whack three! I suddenly remember what it was like to learn Perl the first time again. Boy do I feel confused. It's starting to work though. Kinda like the first Perl CGI I wrote about seven years ago. Probably just as ugly too. Anyone want to join in here, please feel free! #!/usr/bin/pugs print content-type: text/html\n\n; my %q = (); my @q = split '', %ENV.{'QUERY_STRING'}; for (@q) { my ($n, $v) = split '=', $_; decode($n); decode($v); if (none(%q.{$n})) { %q.{$n} = [$v] } else { %q.{$n}.push($v) } } for (%q.keys) { say $_ = ~%q.{$_}.join(', ')~'br' } sub decode($input is rw) { $input ~~ s:Perl5:g/\+/ /; $input ~~ s:Perl5:g/%(..)/{chr(:16[0x$0])}/; } --michael PS Sorry, read the fine print. I'm not Columbian, it was just the lowest valued denomination I could find. I reckon it comes to about US$0.41 in total. But, to show what a stand-up guy I am, I will give you that amount if we ever meet. I'm in London at the moment. Can you make it?
Re: CGI on 6
Michael, 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. Cheers, Ovid -- If this message is a response to a question on a mailing list, please send follow up questions to the list. Web Programming with Perl -- http://users.easystreet.com/ovid/cgi_course/
Re: CGI on 6
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)? Yes, this is a learning exercise (you may provide links to the real pugs CGI solution -- it's not easy to find) but any advice you give could possibly be a learning experience for more than just me. --michael
Re: CGI on 6
- 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 %ENVQUERY_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
Re: CGI on 6
On Mon, May 29, 2006 at 05:28:53PM -0700, Ovid wrote: 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 %ENVQUERY_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); Why not let this auto-vivify? E.g.: $ pugs -e 'my %e; %ea.push: 1,2,3; say %e;' a 1 2 3 I'm kind of surprised that worked, with the OO syntax. But is it considered bad style? I use it constantly in perl5... those constant tests for existence are so obnoxious in other languages, though I like Ruby's approach. joel
Re: CGI on 6
On Mon, May 29, 2006 at 05:28:53PM -0700, Ovid wrote: 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 ... Ah, should have paid more attention. What about: $nv.split('=').map: decode joel
CGI on 6
Thinking about the wiki on 6 challenge (would that be a pliki? a sixwiki? a plixi? erm-) I think the first hurdle would be getting CGI going on 6. Is this already proven? If so how? I'm investigating this now, but if someone wants to offer a working example... --michael
Re: CGI on 6
* Michael Mathews [EMAIL PROTECTED] [2006-05-28 10:10]: (would that be a pliki? a sixwiki? a plixi? erm-) Pliki Sixi? Regards, -- #Aristotle *AUTOLOAD=*_;sub _{s/(.*)::(.*)/print$2,(,$\/, )[defined wantarray]/e;$1}; Just-another-Perl-hacker;
Re: CGI on 6
Here's my first stab at a perl 6 cgi script. It's unusably slow under pugs, but that's a problem for the optimisation people :-) not me! If I'm reinventing the wheel here just tell me, but it's still a useful learning exercise (I'm embarrassed to tell you how long this took me to get working!). Wanna add code for the TODO's? begin code #!/usr/bin/pugs say content-type: text/html\n\n; my %q = (); my @q = split '', %ENV.{'QUERY_STRING'}; for (@q) { my ($n, $v) = split '=', $_; # TODO: deal with URI encoding # similar to perl5: s/%(..)/pack(c,hex($1))/ge; #TODO: handle multiple values and same key %q.{$n} = $v; } for (%q.keys) { say $_, = , %q.{$_}, br; } end code --michael
Re: CGI on 6
* Michael Mathews [EMAIL PROTECTED] [2006-05-28 11:40]: #!/usr/bin/pugs say content-type: text/html\n\n; my %q = (); my @q = split '', %ENV.{'QUERY_STRING'}; for (@q) { my ($n, $v) = split '=', $_; # TODO: deal with URI encoding # similar to perl5: s/%(..)/pack(c,hex($1))/ge; #TODO: handle multiple values and same key %q.{$n} = $v; } for (%q.keys) { say $_, = , %q.{$_}, br; } Flying blindly (ie. no Pugs installed): my @q = split //, %ENVQUERY_STRING == map { split /=/, $_, 2 } == map { $_ # TODO: deal with URI encoding }; say Content-type: text/plain\n\n; for @q - $key, $val { say $key = $val } } I’d like to know if there’s a way to write `split` as a method call, though, in which case the explicit `$_` could go away by merely invoking the `split` method on the topic, something like this maybe: map { .split /=/, 2 } I’d also like to know if there’s a way to use the `-` pointy with `map` in order to walk lists several elements at a times and to assign name(s) for the iterator(s) instead of having to use the topic. Regards, -- #Aristotle *AUTOLOAD=*_;sub _{s/(.*)::(.*)/print$2,(,$\/, )[defined wantarray]/e;$1}; Just-another-Perl-hacker;
RE: CGI on 6
From: Michael Mathews [mailto:[EMAIL PROTECTED] Sent: Sunday, May 28, 2006 2:38 AM Here's my first stab at a perl 6 cgi script. It's unusably slow under pugs, but that's a problem for the optimisation people :-) not me! If I'm reinventing the wheel here just tell me, Don't know off-hand, but here's some links I know about Haven't checked these out much, but the subdirectories have a little code: http://svn.perl.org/perl6/pugs/trunk/examples/cgi/ More code here (and in subdirectories): https://svn.perl.org/perl6/pugs/trunk/ext/CGI I've not looked much beyond this page, but it looked interesting: http://search.cpan.org/dist/WWW-Kontent/WWW/Kontent.pm BTW, I couldn't find this by doing a (search.cpan) search on Perl 6, which may mean that there is a substantial amount of other interesting Perl 6 stuff that many people are not finding. Looks like this was reserved for your personal use. :-) http://svn.perl.org/perl6/pugs/trunk/examples/cookbook/19cgi-programming/ HTH. Best regards, Conrad Schneiker www.athenalab.com/Perl_6_Users_FAQ.htm www.AthenaLab.com (Nano-electron-beam and micro-neutron-beam technology.)
Re: CGI on 6
sixwiki? a plixi? erm-) I think the first hurdle would be getting CGI going on 6. Is this already proven? If so how? Not first ;-) http://real.perl6.ru/p6/environment/ http://real.perl6.ru/p6/querystring/?one=alphatwo=betathree=gammaemptyfour=delta http://real.perl6.ru/p6/cookie/ (refresh twice) http://real.perl6.ru/p6/queryhash/?one=alphatwo=betathree=gammaemptyfour=delta -- Andrew Shitov __ [EMAIL PROTECTED] | http://www.shitov.ru
Re: CGI on 6
On 28/05/06, Andrew Shitov [EMAIL PROTECTED] wrote: Not first ;-) http://real.perl6.ru/p6/environment/ http://real.perl6.ru/p6/querystring/?one=alphatwo=betathree=gammaemptyfour=delta http://real.perl6.ru/p6/cookie/ (refresh twice) http://real.perl6.ru/p6/queryhash/?one=alphatwo=betathree=gammaemptyfour=delta This doesn't appear to deal with URI encoding, or even the s/+/ / task (though I admit, dealing with perl6 and Russian on the same page makes my eyes water). Is there a reason you don't use a regex substitution? For that matter can anyone give a working (under pugs) example of a simple substitution using Perl6 regex, + = for example? --michael
Re: CGI on 6
* Michael Mathews [EMAIL PROTECTED] [2006-05-28 16:15]: For that matter can anyone give a working (under pugs) example of a simple substitution using Perl6 regex, + = for example? I think you’ll end up doing s:p5/// or however exactly it is spelled where you can just write a Perl 5 regex. Regards, -- #Aristotle *AUTOLOAD=*_;sub _{s/(.*)::(.*)/print$2,(,$\/, )[defined wantarray]/e;$1}; Just-another-Perl-hacker;
Re: CGI on 6
On 28/05/06, A. Pagaltzis [EMAIL PROTECTED] wrote: I think you'll end up doing s:p5/// or however exactly it is spelled where you can just write a Perl 5 regex. #!/usr/bin/pugs my $v = one+two+three; $v =~ s/+/ /; print $v; prints... Subst What's Subst mean? Do I need to do something special to get the substitute-affected value back? I get the same result with s:p5. Also is the operator ~~ or =~? I've found contradictory references to both in books and online. --michael
Re: CGI on 6
Michael Mathews skribis 2006-05-28 15:46 (+0100): $v =~ s/+/ /; That is: $v = (~ s/+/ /); What's Subst mean? That is how Pugs stringifies s/+/ /, as requested with the stringification operator ~ Also is the operator ~~ or =~? I've found contradictory references to both in books and online. It was =~ in Perl 5, but it's ~~ in Perl 6. Please report occurrences of =~ to the respective authors. The negated version is !~, as it was in Perl 5. Juerd -- http://convolution.nl/maak_juerd_blij.html http://convolution.nl/make_juerd_happy.html http://convolution.nl/gajigu_juerd_n.html
Re: CGI on 6
- Original Message From: Conrad Schneiker [EMAIL PROTECTED] More code here (and in subdirectories): https://svn.perl.org/perl6/pugs/trunk/ext/CGI I'm on a friend's computer so I can't check that, but I seem to recall that that interface was borrowed directly from Perl5's CGI.pm. This might be an opportunity to consider taking care of any nits we might have with that module as the stuff which is in ext/ might get sent to the CPAN. In fact, anyone who has gripes about the interface of various Perl5 modules might want to consider this opportunity ... Looks like this was reserved for your personal use. :-) http://svn.perl.org/perl6/pugs/trunk/examples/cookbook/19cgi-programming/ The cookbook project bogged down terribly after some initial great momentum. If anyone wants to write some recipes, I can't speak for Audrey, but she was quite willing to hand out committer bits and I suspect she'd be happy to have more of the cookbook fleshed out. We need it very badly! Cheers, Ovid -- If this message is a response to a question on a mailing list, please send follow up questions to the list. Web Programming with Perl -- http://users.easystreet.com/ovid/cgi_course/
Re: CGI on 6
On 28/05/06, Juerd [EMAIL PROTECTED] wrote: Michael Mathews skribis 2006-05-28 15:46 (+0100): Also is the operator ~~ or =~? I've found contradictory references to both in books and online. It was =~ in Perl 5, but it's ~~ in Perl 6. Please report occurrences of =~ to the respective authors. Well, one example would be Damian's Exegesis 5 at http://dev.perl.org/perl6/doc/design/exe/E05.html which I thought was an authorative word on the subject. Can you give me a link to working examples of regex in pugs please? I did try $foo ~~ s/foo/bar/; of course, but that results in an even more ominous sounding error: *** Cannot parse PGE: foo *** Error: does not exist fooSegmentation fault And, as an incentive, I'm offering 1000 Colombian Pesos to the first person to author a working example of s/+/ /g; in Perl 6*. --michael *offer will not actually be honoured.
Re: CGI on 6
Michael Mathews skribis 2006-05-28 20:32 (+0100): And, as an incentive, I'm offering 1000 Colombian Pesos to the first person to author a working example of s/+/ /g; in Perl 6*. If your PGE support works, s/+/ /g still does not. It's s:g/\+/ /. Juerd -- http://convolution.nl/maak_juerd_blij.html http://convolution.nl/make_juerd_happy.html http://convolution.nl/gajigu_juerd_n.html
Re: CGI on 6
Michael Mathews skribis 2006-05-28 20:32 (+0100): Well, one example would be Damian's Exegesis 5 at http://dev.perl.org/perl6/doc/design/exe/E05.html which I thought was an authorative word on the subject. Can you give me a link to working examples of regex in pugs please? The exegeses are not updated to follow the current specifications. They're still useful, so they're kept around, but the syntax is out of date. Synopses are kept up to date. See http://dev.perl.org/perl6/doc/design/syn/S05.html *** Cannot parse PGE: foo That means: PGE is currently broken, so Perl 6 regexes don't work in Pugs. And, as an incentive, I'm offering 1000 Colombian Pesos to the first person to author a working example of s/+/ /g; in Perl 6*. $foo ~~ s:Perl5:g/\+/ /; Juerd -- http://convolution.nl/maak_juerd_blij.html http://convolution.nl/make_juerd_happy.html http://convolution.nl/gajigu_juerd_n.html