#!/usr/bin/perl use strict; use warnings; use File::Spec; use Cache::FileCache (); unless ( @ARGV ) { my $script = (File::Spec->splitpath($0))[2]; die "$script another_program -and -its -args\n" . "caches the output from the command and only prints if it differs fro" . "m the last time $script was run. This allows you to say `$script who" . "is -i somedomain.org` and only have output show up when the whois ou" . "tput changes\n"; } my $pid; my $sleep_count = 0; do { $pid = open KID_TO_READ, "-|", @ARGV; unless (defined $pid) { warn "cannot fork: $!"; die "bailing out" if $sleep_count++ > 6; sleep 10; } } until defined $pid; my $self = File::Spec->rel2abs( $0 ); my $cache = Cache::FileCache->new( { namespace => $self } ); my $old = $cache->get( "@ARGV" ); my $new = do { local $/; }; if ($new ne $old) { print $new; $cache->set( "@ARGV", $new ); } close KID_TO_READ or warn "kid exited $?";