Just minor changes, obviously.#!/usr/bin/perl -w use strict; use Fcntl qw(:DEFAULT :flock); use File::Temp qw(tempfile); use File::Spec::Functions qw(tmpdir); use File::Basename; my $editor = $ENV{EDITOR} || 'vi'; File::Temp->safe_level(2); my ($tfh, $fname) = tempfile( basename($0).".XXXXXXX", DIR => tmpdir(), UNLINK => 1, ); select((select($tfh), $|++)[0]); print $tfh <<"INTRO"; Default text to appear in editor. INTRO # File::Temp locks the file by default # which is not productive with external editors flock $tfh, LOCK_UN; my $status = system $editor, $fname; die($status != -1 ? "external editor $editor failed with $?\n" : "couldn't launch external editor $editor: $!\n" ) unless $status == 0; seek $tfh, 0, 0 or die "Error seeking on temp file: $!\n"; my $data = do { local $/; <$tfh> };
Makeshifts last the longest.
In reply to Re: Soliciting input via a tempfile passed to an external editor
by Aristotle
in thread Soliciting input via a tempfile passed to an external editor
by thrig
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |