Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tac: add usage #269

Merged
merged 1 commit into from
Sep 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions bin/tac
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,20 @@ License: perl
# tac - concatenate and print files in reverse
#

use Getopt::Std;
use File::Basename qw(basename);
use Getopt::Std qw(getopts);

my $VERSION = '0.17';
use constant EX_SUCCESS => 0;
use constant EX_FAILURE => 1;

getopts('bBrs:S:', \my %opts);
my $Program = basename($0);
my $VERSION = '0.18';

unless (getopts('bBrs:S:', \my %opts)) {
warn "$Program version $VERSION\n";
warn "usage: $Program [-br] [-s separator] [-B] [-S bytes] [file...]\n";
exit EX_FAILURE;
}
my %long = qw/
b before
B binary
Expand All @@ -39,11 +48,16 @@ if (defined $opts{separator} && $opts{regex}) {

$opts{files} = \@ARGV;

my $fh = IO::Tac->new(%opts) or die "$0: can't open file: $!\n";
my $fh = IO::Tac->new(%opts);
unless ($fh) {
warn "$Program: can't open file: $!\n";
exit EX_FAILURE;
}
print while <$fh>;
exit EX_SUCCESS;

END {
close STDOUT || die "$0: can't close stdout: $!\n";
close STDOUT || die "$Program: can't close stdout: $!\n";
$? = 1 if $? == 255; # from die
}

Expand Down