From 67de09d00b52e60c3bbffaf266a37c28af37fe65 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Thu, 8 Apr 2010 08:44:37 +0200 Subject: [PATCH] Tool for running a command on the newest non-directory Example: run_match_latest.pl gdb will run gdb on the latest non-directory file in the current directory, which is hopefully a core file. --- bin/run_match_latest.pl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100755 bin/run_match_latest.pl diff --git a/bin/run_match_latest.pl b/bin/run_match_latest.pl new file mode 100755 index 0000000..7237c89 --- /dev/null +++ b/bin/run_match_latest.pl @@ -0,0 +1,15 @@ +#!/usr/bin/perl -w + +# Run a given program on the newest non-directory in a given directory + +use strict; +$|++; +my $program = shift || die "Must give program to run with latest file"; +my $dir = shift || './'; + +opendir (my $d, $dir) or die $!; + +my @files = sort { -M $b <=> -M $a } grep { !-d $_ } readdir ($d); +print "Running: $program " . $files[-1] . "\n"; +system($program, $files[-1]); +closedir ($d);