From c80e7d8e6b17c2e531608b33c1864200becbbe4e Mon Sep 17 00:00:00 2001 From: Kharec Date: Tue, 18 Nov 2025 07:35:39 +0100 Subject: [PATCH] refactor: extract file-reading logic into a helper function --- m2h.pl | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/m2h.pl b/m2h.pl index 24c7d34..98bd873 100755 --- a/m2h.pl +++ b/m2h.pl @@ -23,6 +23,19 @@ sub show_version { exit 0; } +sub read_input { + my ($file) = @_; + local $/; + if ($file) { + open my $fh, '<', $file + or die "Error: Cannot open file: $file\n"; + my $content = <$fh>; + close $fh; + return $content; + } + return ; +} + my $output_file; my $input_file; @@ -46,18 +59,7 @@ for ( my $i = 0 ; $i < @ARGV ; $i++ ) { } } -my $input; -if ($input_file) { - open my $fh, '<', $input_file - or die "Error: Cannot open file: $input_file\n"; - local $/; - $input = <$fh>; - close $fh; -} -else { - local $/; - $input = ; -} +my $input = read_input($input_file); my $output; if ($output_file) {