#!/usr/bin/perl

=begin metadata

Name: rev
Description: reverse lines of a file
Author: Andy Murren, andy@murren.org
License: gpl

=end metadata

=cut

use strict;

# unbuffer output to make it look speedier
$|++;

my ($VERSION) = '1.3';

if (scalar(@ARGV) == 0 || $ARGV[0] !~ m/^-/) {
	while (<>) {
		chomp;
		my $r = reverse($_);
		print $r . $/;
	}
	die("$0: $!") if $!;
}
elsif ($ARGV[0] eq '--version') {
	print " $0 $VERSION\n";
}
else {
	print <<EOF;
Usage: $0 [OPTION] [FILE]

Reverses lines of the named file or the text input on STDIN

Options:
	--version:  Print version number, then exit.
	--help || -h:     Print usage, then exit;

EOF
	exit 1;
}

exit;

__END__

=pod

=head1 NAME

rev - reverse lines of a file

=head1 SYNOPSIS

rev [options] [file]

=head1 DESCRIPTION

The rev utility copies the specified files to the standard output,
reversing the order of characters in every line.  If no files are
specified, the standard input is read.

=head2 OPTIONS

I<rev> accepts the following options:

=over 4

=item  --help || -h

Print a short help message, then exits.

=item  --version

Prints out its version number, then exits.

=back

=head1 BUGS

I<rev> has no known bugs.

=head1 AUTHOR

This Perl implementation of I<rev> was written by Andy Murren,
I<andy@murren.org>.

=head1 COPYRIGHT and LICENSE

This program is covered by the GNU Public License (GPL).
See I<http://www.gnu.org/copyleft/gpl.html> for complete detail of the license.

=cut
