Experimenting and trying things, especially for this discussion group, I find that a lot of things are one-liners that can be done via -e. Some are difficult to do because of shell quoting issues, and some are a couple lines. Creating a file in the text editor, deciding on a name and saving it, then going to that directory on a command-line to run it seems overkill for something I should be able to do with -e or something like it.

So I've had it in the back of my head to make something as a shortcut. Implementing a "run contents as Perl" command for my usual text editor has issues: I still have to come up with a name, and it's not running under a console (text) environment.

So, I thought about a real simple Perl program that has a edit box and a Run button. (see end for concept code)

Now that it's underway, I'm thinking about other features. Here's a question: How can I separate out compiler errors from program's output? The program may itself write to STDERR, so if I can get Perl to write to someplace else... then the editor can parse errors and position the cursor. Note that I'm running another copy of Perl, not simply eval-ing the code, so it can always have a clean environment.

All thoughts welcome.

—John

use strict; use warnings; use utf8; use Tk; ${^WIDE_SYSTEM_CALLS}= 1; my $MW = new MainWindow; my $text= $MW->Scrolled(qw/Text -relief sunken -borderwidth 2 -wrap no +ne -height 30 -scrollbars e/) ->pack(qw/-expand yes -fill both/); my $frame= $MW->Frame()->pack(); $frame->Button( -text => 'Run', -command => \&do_run ) ->pack (-side => 'left'); $frame->Button( -text => 'Save' ) -> pack (-side =>'left'); $text->insert ('0.0', "use v5.6.1;\nuse strict;\nuse warnings;\n\n"); MainLoop; ################3 sub do_run { my $s= $text->get('1.0','end'); open OUTFILE, "> quick_run.perl" or die "Cannot save file."; print OUTFILE $s; close OUTFILE; system "perl quick_run.perl"; }

In reply to QuickPerl: a step up from -e by John M. Dlugosz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.