From: Steve Hancock Date: Sun, 22 Mar 2020 23:42:54 +0000 (-0700) Subject: cleaned up backup-in-place coding to use streamhandle X-Git-Tag: 20200619~120 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=780503433f87c4f8c27d33082efbcb5219543624;p=perltidy.git cleaned up backup-in-place coding to use streamhandle --- diff --git a/lib/Perl/Tidy.pm b/lib/Perl/Tidy.pm index 90abd8c5..6523b228 100644 --- a/lib/Perl/Tidy.pm +++ b/lib/Perl/Tidy.pm @@ -1421,15 +1421,13 @@ EOM seek( $output_file, 0, 0 ) or Die("unable to rewind a temporary file for -b option: $!\n"); - # TODO: maybe use streamhandle here - my $fout = IO::File->new("> $input_file") - or Die( + my ( $fout, $iname ) = + Perl::Tidy::streamhandle( $input_file, 'w', $is_encoded_data ); + if ( !$fout ) { + Die( "problem re-opening $input_file for write for -b option; check file and directory permissions: $!\n" - ); - if ($is_encoded_data) { - binmode $fout, ":raw:encoding(UTF-8)"; + ); } - else { binmode $fout } my $line; while ( $line = $output_file->getline() ) {