Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Web based perl REPL

by BUU (Prior)
on Dec 03, 2006 at 20:38 UTC ( #587542=perlmeditation: print w/replies, xml ) Need Help??

For a while now I've been playing with safe line based evaluation of perl code over IRC, which via commans containing perl code submitted to an IRC bot, who executes the code and returns the results. This is cool and all, but recently it ocurred to me that I could use much the same code and place it on the internet, perhaps with more usefulness. Around that time integral wrote Devel::EvalContext which allowed one to save the lexical state of an eval. The combination naturally led to a Web Based REPL, which stands for "Read Eval Print Loop".

Read Eval Print Loops are commonly found on the CLI for various programming languages, examples being ruby and python I believe. perl -de1 is more or less an example of a perl REPL.

In any case, I thought I'd show off my new repl by linking it here, check it out at:

So far it's stood up to fairly extensive security testing, and should be fully secure, but please let me know if something doesn't look right to you.

Update: Upvotes are all well and good, but I'd much prefer actual replies! Preferably with suggestions, either for the interface or for some actual use for this thing!

Replies are listed 'Best First'.
Re: Web based perl REPL
by stvn (Monsignor) on Dec 03, 2006 at 21:08 UTC

    Looks pretty cool, one problem I noticed was in your handling of \n in the P of the loop. I tried this:

    > print $_, "\n" for (1 .. 10)
    and it only printed '1', and nothing else. I suspect you need to read in all the lines returned, then join it with a HTML br tag or something.

      You are very correct, I'm afraid it's been a long standing bug. My essential problem is I have no real way of telling when the output has ended, so at the moment I just read the first line and return that.

      Also while I'm listing bugs, it doesn't handle STDERR very well. Or at all. =[
        Perhaps you could append a ;print "END_OF_OUTPUT\n"; to the code that was sent in and then read until that. I'm not sure how your loop works, but you could probably also append a value to "END_OF_OUTPUT" that doesn't occur within the code.
Re: Web based perl REPL
by NetWallah (Canon) on Dec 04, 2006 at 04:10 UTC
    This is not behaving as I expect, when matching a single Regex:
    > my $x='this is a test' this is a test > $x=~m/(.+)a/ 1 > $1 > print $1 1
    I was expecting $1 to contain "this is ".
    ++ anyway, for a good idea looking for an application.

    Update:I can get the results I want using alternative syntax:

    > my $x='This is a test for web perl parsing'; This is a test for web perl parsing > my ($what_test) = $x =~m/for (.+)/; 1> $what_test web perl parsing
    So Regexen work fine - its just the $1..$n appear not to be available.

         "A closed mouth gathers no feet." --Unknown

      You're losing $1 because it's doing other regexen in between executions.
Re: Web based perl REPL
by bibliophile (Parson) on Dec 04, 2006 at 04:52 UTC
    Hmm, that's really interesting. I'm drawing a blank on "acutal uses", but as far as interface stuff... could you do some kind of multiple frame thingy, with STDERR going to the second frame?

    Just a thought (which, per normal, may not make any sense at all...)

    -- WARNING: You are logged into reality as root.
Re: Web based perl REPL
by gaal (Parson) on Dec 04, 2006 at 06:44 UTC
    It seems to be appending the result of an evaluation to the output without any whitespace.

    > print 42*1; 421 > print 2; 21 > 42; 42

Re: Web based perl REPL
by Limbic~Region (Chancellor) on Dec 05, 2006 at 00:52 UTC
    It wasn't very hard to break. If breaking it is what I did.
    my $sub = sub { print "hello\n"; }; $sub->();
    I will play more after this is fixed ;-)

    Cheers - L~R

Re: Web based perl REPL
by Anonymous Monk on Dec 04, 2006 at 06:43 UTC
    So far it's stood up to fairly extensive security testing, and should be fully secure, but please let me know if something doesn't look right to you.

    Where is the code?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://587542]
Approved by grep
and a log crumbles through the grate...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2018-06-20 06:00 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (116 votes). Check out past polls.