#!/usr/bin/perl
our
$VERSION
= 0.001_000;
sub
tac {
{
my
void
$RETURN_TYPE
};
(
my
string_arrayref
$command_line_arguments
) =
@ARG
;
$command_line_arguments
= [
reverse
@{
$command_line_arguments
} ];
foreach
my
string
$file_name
( @{
$command_line_arguments
} ) {
if
( not( -e
$file_name
) ) {
croak
'ERROR: File '
,
$file_name
,
' does not exist, croaking'
;
}
if
( not( -r
$file_name
) ) {
croak
'ERROR: File '
,
$file_name
,
' is not readable, croaking'
;
}
if
( not( -f
$file_name
) ) {
croak
'ERROR: File '
,
$file_name
,
' is not a regular file, croaking'
;
}
if
( not( -T
$file_name
) ) {
croak
'ERROR: File '
,
$file_name
,
' is (probably) not text, croaking'
;
}
my
integer
$open_success
=
open
my
filehandleref
$FILE
,
'<'
,
$file_name
;
if
( not
$open_success
) {
croak
'ERROR: Failed to open file '
,
$file_name
,
' for reading, croaking'
;
}
my
string_arrayref
$file_lines
= [];
while
(
my
string
$file_line
= <
$FILE
> ) {
push
@{
$file_lines
},
$file_line
;
}
$file_lines
= [
reverse
@{
$file_lines
} ];
foreach
my
string
$file_line
( @{
$file_lines
} ) {
print
$file_line
;
}
if
( not
close
$FILE
) {
croak
'ERROR: Failed to close file '
,
$file_name
,
' after reading, croaking'
;
}
}
return
;
}
tac( [
@ARGV
] );