#!/usr/bin/env perl use utf8; ############################################################################### # This program simply copies one file to another, character by # character like the Unix 'cat' program. # # Copyright © 2020 Richard Lesh. All rights reserved. ############################################################################### use Error::Simple; use Nice::Try; use Utils; use strict; use warnings; sub copy_text_file { my ($from_filespec, $to_filespec) = @_; my $ifh; my $is_good = open($ifh, "<", $from_filespec); if (!$is_good) { die Error::IOException->new("Problem opening output file!"); } my $ofh; $is_good = open($ofh, ">", $to_filespec); if (!$is_good) { die Error::IOException->new("Problem opening output file!"); } binmode($ifh, ":utf8"); binmode($ofh, ":utf8"); my $c; while (defined($c = Utils::getchar(*$ifh))) { print $ofh chr($c); } close($ifh); close($ofh); } MAIN: { binmode(STDOUT, ":utf8"); binmode(STDERR, ":utf8"); binmode(STDIN, ":utf8"); if (scalar(@ARGV) != 2) { print "Syntax: ", "FileIO7", " \{fromFilespec\} \{toFilespec\}\n"; exit 1; } my $from_filespec = $ARGV[0]; my $to_filespec = $ARGV[1]; try { copy_text_file($from_filespec, $to_filespec); } catch (Error::IOException $ex) { print "Error: ", $ex, "\n"; } }