CodeChallenge#

Wer schafft die ARC-Aufgabe von Paul Graham unter http://arclanguage.org/item?id=722 in weniger Code:

Hier noch einmal die Aufgabe:

Zuerst erzeuge eine Seite mit einem Eingabefeld und einem Absende-Button. Sobald der Anwender auf Submit drückt, erscheint eine zweite Seite mit einem Link "click here". Wenn er dem Link folgt, erhält er eine dritte Seite mit dem Text

 "you said: ..." 

- wobei ... den Eintrag im ersten Eingabefeld darstellt.

Der Eingabetext darf nicht in der URL weitergegeben werden, damit das Verhalten der dritten Seite im zweiten Schritt nicht manipuliert werden kann.

Originalaufgabe:
Here's what it has to do. First generate a page with an input field and a submit button. If the user clicks on submit, he gets a second page with a link saying "click here." If he clicks on that, he gets a third page saying "you said: ..." where ... was whatever he put in the input field. This has to happen without the value being passed in the url; it should not be possible to change the behavior of the third page by editing the url in the second.

--MarkusMonderkamp am 26.03.2008

originale ARC-Lösung#

 (defop said req
    (aform [w/link (pr "you said: " (arg _ "foo"))
             (pr "click here")]
      (input "foo")
      (submit)))

Perl-Vorschlag#

  #!/usr/bin/perl
  use Continuity;
  Continuity->new->loop; # This starts the webserver
  sub main {
    my $request = shift;
    $request->print("<form><input type=text name=foo><input type=submit>");
    my $foo = $request->next->param('foo');
    $request->print("<a href='.'>Click Here</a>");
    $request->next->print("You said: $foo");
  }

Andere Lösung mit CGI::Session

        #!/usr/bin/perl
        use strict;
        use warnings;
        use CGI;
        use CGI::Session;
        my $cgi     = new CGI;
        my $session = new CGI::Session();
        print $session->header();
        $session->param('name', $cgi->param('name')) if ($cgi->param("name"));
        $session->clear('name')                      if ($cgi->param("c"));
        if ($cgi->param("m") eq 'show') {
          print "You said:", $session->param("name"), " ", $cgi->a({href=>'?c=1'},'Start Over');
        } elsif ($session->param("name")) {
          print $cgi->a({href=>'?m=show'},'See what you said');
        } else {
          print $cgi->startform, $cgi->textfield('name'), $cgi->submit('Submit'), $cgi->endform;
        } 

Add new attachment

Only authorized users are allowed to upload new attachments.
« This page (revision-1) was last changed on 26-Mar-2008 10:13 by MarkusMonderkamp