diff --git a/bin/rev b/bin/rev index c3a4e5bf..82a123ee 100755 --- a/bin/rev +++ b/bin/rev @@ -14,6 +14,7 @@ License: gpl use strict; use File::Basename qw(basename); +use Getopt::Std qw(getopts); use constant EX_SUCCESS => 0; use constant EX_FAILURE => 1; @@ -25,48 +26,33 @@ $|++; my ($VERSION) = '1.4'; -my $rc = EX_SUCCESS; -if (scalar(@ARGV) == 0 || $ARGV[0] !~ m/^-./) { - if (@ARGV) { - foreach my $file (@ARGV) { - if (-d $file) { - warn "$Program: '$file' is a directory\n"; - $rc = EX_FAILURE; - next; - } - my $fh; - unless (open $fh, '<', $file) { - warn "$Program: cannot open '$file': $!\n"; - $rc = EX_FAILURE; - next; - } - rev($fh); - if ($!) { - warn "$Program: '$file': $!\n"; - $rc = EX_FAILURE; - } - } - } else { - rev(*STDIN); - } +my %opt; +getopts('v', \%opt) or usage(); +if ($opt{'v'}) { + print "$Program $VERSION\n"; + exit EX_SUCCESS; } -elsif ($ARGV[0] eq '--version') { - print " $Program $VERSION\n"; -} -else { - print < accepts the following options: =over 4 -=item --help || -h - -Print a short help message, then exits. - -=item --version +=item -v -Prints out its version number, then exits. +Print version number then exit =back