in reply to Simple REPL madness.

Wouldn't it be much easier to just delete all code above (and including) the __DATA__ marker and run what remains?

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Replies are listed 'Best First'.
Re^2: Simple REPL madness.
by tilly (Archbishop) on Dec 22, 2008 at 08:48 UTC
    That would not run each line as it is typed. That would also let lexical scopes work, and make a number of other differences.

      Correct, although I feel it's worth pointing out that this code actually checks for a sentinel value (a bang on a line of its own) rather than evaluating each expression as entered.

      Also, I just realized, in order to be a proper REPL, it really should be print eval ...

      for(split(" ","tsuJ rehtonA lreP rekcaH")){print reverse . " "}print "\b.\n";
Re^2: Simple REPL madness.
by pobocks (Chaplain) on Dec 22, 2008 at 08:52 UTC

    What he said ::points at tilly's comment::

    The interesting (for some values of interesting) part of this is the immediate interpretation. Of course, there's a much more functional Read-Eval-Print-Loop available at perl -d. But I found it interesting from a "oooh, lookie what weirdness the DATA handle can be used for" perspective.

    for(split(" ","tsuJ rehtonA lreP rekcaH")){print reverse . " "}print "\b.\n";
      Thank you for eventually explaining what the *bleep* a 'REPL' is.

      --
      In Bob We Trust, All Others Bring Data.

        Sorry; I guess I've read one too many Lisp books, and took it for a common term ;-)

        for(split(" ","tsuJ rehtonA lreP rekcaH")){print reverse . " "}print "\b.\n";