The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#!/usr/bin/perl
# rev - reverse the lines of a file
# VERSION 1.0
 
END {
    close STDOUT || die "$0: can't close stdout: $!\n";
    $? = 1 if $? == 255;  # from die
}

foreach my $i (0..$#ARGV) {
    my $item=$ARGV[$i];
    $item =~ /^--$/   and  (splice @ARGV,$i,1) , last;
    $item =~ /^-\?$/  and   manual();          # exits
}

while (<>) {
    chomp;
    print +(scalar reverse), "\n";
}

sub manual {
    open  MAN, "|pod2text" or die "$0: Cannot open pod2text converter\n";
    print MAN  <DATA>;
    close MAN;
    exit;
}

__END__

=head1 NAME

rev - reverse the lines of a file

=head1 SYNOPSIS

rev B<[file ...]>

=head1 DESCRIPTION

I<rev> reverses each line of each file given as a command-line 
argument, returning the result on the standard output.  If no 
arguments are given, I<rev> will read from the standard input. 

=head1 ENVIRONMENT

No environment variables affect the execution of I<rev>.

=head1 BUGS

I<rev> has no known bugs.

=head1 AUTHOR   

D Roland Walker, I<E<lt>walker@pobox.comE<gt>>.

=head1 COPYRIGHT and LICENSE

This program is copyright (c) D Roland Walker 1999.

This program is free and open software. You may use, modify, distribute,
and sell this program (and any modified variants) in any way you wish,
provided you do not restrict others from doing the same.