$ cat nibley1.pm package nibley1; require Exporter; use config1; use utils1; our @ISA = qw(Exporter); our @EXPORT = qw( text_to_captions ); sub get_text { use 5.010; use File::Slurp; my ($rvars) = shift; my %vars = %$rvars; my $word_hash_ref = zip_lists( $vars{'words'}, $vars{'subs'} ); my %hash = %$word_hash_ref; my $check = join '|', keys %hash; open( my $hh, "<:encoding(UTF-8)", $vars{'source'} ) || die "can't open UTF-8 encoded filename: $!"; my $text; while (<$hh>) { $_ =~ s/($check)/$hash{$1}/gi; $_ =~ s/[^[:ascii:]]+/ /g; # $_ =~ s%
%%; say "default is $_"; $text = $text . $_; } return $text; } sub text_to_captions { use 5.010; use File::Slurp; use Path::Class; my ($rvars) = shift; my %vars = %$rvars; my $text = get_text($rvars); say "text is $text"; my $name = $vars{"book"} . $vars{"chapter"} . '.' . "txt"; say "name is $name"; my $temp = $vars{"path"}; say "temp is $temp"; my $file = file( $vars{"path"}, $name ); say "file is $file"; open( my $fh, ">:encoding(UTF-8)", $file ) or die("Can't open $file for writing: $!"); print $fh $text; close $fh; } 1;