use
5.014;
use
constant
usageText
=>
"Usage: perl $Script inputfile.txt outputfile.txt"
;
sub
main {
my
(
undef
,
undef
,
@args
) =
@_
;
if
(
@args
< 2) {
Console->WriteLine(usageText);
return
1;
}
eval
{
if
(
my
$writer
= IO::File->new(
$args
[1],
'w'
) ) {
if
(
my
$reader
= IO::File->new(
$args
[0],
'r'
) ) {
Console->SetOut(
$writer
);
Console->SetIn(
$reader
);
my
$line
;
while
(
defined
(
$line
= Console->ReadLine()) ) {
my
$newLine
=
do
{
my
$re
=
' '
x tabSize;
$line
=~ s/
$re
/\t/r };
Console->WriteLine(
$newLine
);
}
}
}
};
if
( $@ ) {
my
$errorWriter
= Console->Error;
$errorWriter
->
say
($@);
$errorWriter
->
say
(usageText);
return
1;
}
my
$standardOutput
= IO::File->new_from_fd(
fileno
(Console->OpenStandardOutput()),
'w'
);
$standardOutput
->autoflush(1);
Console->SetOut(
$standardOutput
);
Console->WriteLine(
"$Script has completed the processing of $args[0]."
);
return
0;
}
exit
main(
@ARGV
+1, $0,
@ARGV
);