#!/usr/bin/perl -wT use Getopt::Long; use Pod::Usage; use Carp; use strict; use File::Basename; my $myname = basename($0); $myname =~ s/\.\w*$//; # strip any extension $ENV{'PATH'} = join ":", qw(/bin /usr/bin /usr/local/bin /opt/sfw/bin); my %options; my @getopt_args = ( 'h|?', # print usage 'm', # print manpage 'u', # print UUID 'v', # print version 'w', # print source location ); Getopt::Long::config("noignorecase", "bundling"); usage() unless GetOptions(\%options, @getopt_args); manpage() if $options{'m'}; myuuid() if $options{'u'}; version() if $options{'v'}; where() if $options{'w'}; usage() if $options{'h'}; # unbuffer output to make it look speedier $|++; while (<>) { chomp; print +(scalar reverse), "\n"; } exit(0); #--------------------------------------------------------------------- # Print a usage message from the comment header and exit. sub usage { my ($emsg) = @_; use Pod::Usage qw(pod2usage); warn "$emsg\n" if defined $emsg; pod2usage(-verbose => 99, -sections => "NAME|SYNOPSIS|OPTIONS"); } sub manpage { use Pod::Man(); my $parser = Pod::Man->new(); open(STDOUT, "| groff -T ascii -man | gcat -s | less") || die "groff\n"; $parser->parse_from_file($0); close STDOUT || die "$myname: can't close stdout: $!\n"; $? = 1 if $? == 255; # from die exit($?); } #--------------------------------------------------------------------- # Print the UUID, current version, or source location. sub myuuid { my $UUID = sprintf("%s", q$UUID: acbc1bec-e84e-3c37-b474-c85d15fe72e2 $ =~ /UUID: (.*) /); print "$UUID\n"; exit(0); } sub version { my $VERSION = sprintf("%d.%02d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/); my $DATE = sprintf("%s", q$Date: 2008/03/05 19:46:37 $ =~ /Date: (.*) /); print "$myname $VERSION $DATE\n"; exit(0); } sub where { my $SOURCE = sprintf("%s", print "$SOURCE\n"; exit(0); } #--------------------------------------------------------------------- __END__ =head1 NAME rev - reverse lines from a file =head1 SYNOPSIS rev [-hmuvw] [file ...] =head1 DESCRIPTION B copies the specified files to stdout, reversing the order of characters in every line. If no files are specified, stdin is read. =head1 OPTIONS =over 4 =item B<-h> Print a brief help message and exit. =item B<-m> Print the manual page and exit. =item B<-u> Print the UUID for this program and exit. =item B<-v> Print the version and exit. =item B<-w> Print the source location and exit. =back =head1 AUTHOR Karl Vogel Sumaria Systems, Inc. Based heavily on ideas from the versions in Perl Power Tools. =cut