Perl implementation of the CVS "solicit log entry by opening up an editor to type into" feature. Creates a temporary file, opens up the editor on the file, then pulls the file contents back into the program.
#!/usr/bin/perl -w use Fcntl qw(:DEFAULT :flock); use File::Temp qw(tempfile); use File::Spec; my $editor = $ENV{EDITOR} || 'vi'; # for naming temp files, so can chase down which app they are coming # from if problems crop up my ($ourname) = $0 =~ /([\w.-]+)$/; $ourname ||= 'perl'; File::Temp->safe_level(2); my ($tfh, $fname) = tempfile("$ourname.XXXXXXX", DIR => File::Spec->tmpdir, UNLINK => 1); # set autoflush to ensure editor gets the right data my $oldfh = select $tfh; $| = 1; select $oldfh; print $tfh <<"INTRO"; Default text to appear in editor. INTRO # File::Temp locks the file by default, which is not productive # with external editors that also want to lock the file. flock $tfh, LOCK_UN; my $status = system "$editor $fname"; die "external editor failed with $?\n" unless $status == 0; # deal with supplied data seek $tfh, 0, 0 or die "Error seeking on temp file: $!\n"; while (<$tfh>) { print; }

In reply to Soliciting input via a tempfile passed to an external editor by thrig

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.