#!/usr/bin/perl use strict; use warnings; use List::Util qw( first ); sub exec_editor { my $filename=shift; my @path=split /:/,$ENV{'PATH'}; my $editor=first { length($_) && -f($_) && -x(_) } map { my $file=$_; /\// ? $file : map { "$_/$file" } @path } ( $ENV{'EDITOR'}//'', $ENV{'VISUAL'}//'', '/usr/bin/editor', # for Debian and friends qw( joe emacs nano vi ), ); defined($editor) or die "Can't find an editor"; exec($editor,$filename) or die "Can't execute $editor: $!"; } @ARGV==1 or die "Usage: $0 file-to-edit\n"; exec_editor($ARGV[0]);