sub get_eng_text { use strict; use 5.010; use File::Basename; use Cwd; use HTML::FromText; use File::Slurp; use Path::Class; my $rvars = shift; my %vars = %$rvars; my %content; my $refc = \%content; opendir my $eh, $vars{"eng_captions"} or die "dead $!\n"; while (defined ($_ = readdir($eh))){ next if m/~$/; next if -d; if (m/txt$/){ my $file = file($vars{"eng_captions"},$_); my $string = read_file($file); my $temp = text2html( $string, urls => 1, email => 1, paras => 1, ); # surround by divs my $oitop = read_file($vars{"oitop"}); my $oibottom = read_file($vars{"oibottom"}); my $text = $oitop.$temp.$oibottom; say "default is $_"; $content{$_} = $text; } } closedir $eh; #important to sort my @return; foreach my $key (sort keys %content) { push @return, $content{$key}; } #say "return is @return"; return \@return; } sub get_rus_text { use 5.010; use File::Basename; use Cwd; use HTML::FromText; use File::Slurp; use Path::Class; my $rvars = shift; my %vars = %$rvars; my %content; my $refc = \%content; opendir my $eh, $vars{"rus_captions"} or die "dead $!\n"; while (defined ($_ = readdir($eh))){ next if m/~$/; next if -d; if (m/txt$/){ my $file = file($vars{"rus_captions"},$_); my $string = read_file($file); # surround by divs my $oitop = read_file($vars{"oitop"}); my $oibottom = read_file($vars{"oibottom"}); my $text = $oitop.$string.$oibottom; $content{$_} = $text; } } closedir $eh; #important to sort my @return; foreach my $key (sort keys %content) { print $content{$key} . "\n"; push @return, $content{$key}; } return \@return; } sub write_body{ use strict; use warnings; use 5.010; use Text::Template; use Encode; my $rvars = shift; my $reftoAoA = shift; my %vars = %$rvars; my @AoA = @$reftoAoA; my $body = $vars{"body"}; my $template = Text::Template->new( ENCODING => 'utf8', SOURCE => $body) or die "Couldn't construct template: $!"; my $return; for my $i ( 0 .. $#AoA ){ $vars{"file"} = $AoA[$i][0]; $vars{"english"} = $AoA[$i][1]; my $ustring = $AoA[$i][2]; $ustring = decode_utf8( $ustring ); $vars{"russian"} = $ustring; my $result = $template->fill_in(HASH => \%vars); $return = $return.$result; } return \$return; } #### sub get_rus_text { use 5.010; use File::Basename; use Cwd; use HTML::FromText; use File::Slurp; use Path::Class; my $rvars = shift; my %vars = %$rvars; my %content; my $refc = \%content; opendir my $eh, $vars{"rus_captions"} or die "dead $!\n"; while (defined ($_ = readdir($eh))){ next if m/~$/; next if -d; if (m/txt$/){ my $file = file($vars{"rus_captions"},$_); my $string = read_file($file); ### revision for better russian use 7/18 my $temp = text2html( $string, urls => 1, email => 1, paras => 1, ); # surround by divs my $oitop = read_file($vars{"oitop"}); my $oibottom = read_file($vars{"oibottom"}); my $text = $oitop.$temp.$oibottom; $content{$_} = $text; } } closedir $eh; #important to sort my @return; foreach my $key (sort keys %content) { print $content{$key} . "\n"; push @return, $content{$key}; } return \@return; }