Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: making the Vater Unser non-sectarian using Text::Template

by Aldebaran (Curate)
on Apr 28, 2019 at 20:56 UTC ( [id://1233092]=note: print w/replies, xml ) Need Help??


in reply to Re: making the Vater Unser non-sectarian using Text::Template
in thread making the Vater Unser non-sectarian using Text::Template

"Vater Unser" ?

I truly don't want to offend and put my response, new code and output between readmore tags:

German has a lot of theological influence on Americans with most of us being too ignorant to know it. Many intellectual giants fled Hitler. The guy who penned our "Serenity Prayer," (Reinhold Niebuhr), was a german expat who wrote it in english. It had to be redacted because saying "Jesus is our model" is sectarian. So, this ends up as something like this:

my $input2 = <<'(END INPUT2)'; {$God} grant me the serenity To accept the things I cannot change; Courage to change the things I can; And wisdom to know the difference. (END INPUT2)

The offending phrase in english comes off with a lot worse associations in german:

dein Reich komme;

The Vater Unser didn't seem very popular to the germans I knew. Put another way, I never heard it once. I studied it first with a plattduutsch Bibel, then Luther, then Einheitsuebersetzung. Lots of new testaments nobody wanted at Antiquariaten I could pick up for a few Groschen. The prayer makes an excellent Rosetta Stone, independent of its theology.

I've been trying to add a couple wide character strings for the substitutions, and what I have now works in that it gets the desired output written to the files, but I don't display it correctly on STDOUT. Output of 2.vater_unser.pl in code tags, followed by source in code tags:

OUTFILES******************* Group Of Drunks, who art in heaven, Hallowed be thy name. Ta ti ti ta, Thy will be done, On earth as it is in heaven. Give us this day our daily bread; And forgive us our trespasses, As we also have forgiven our trespasses; And lead us not into temptation, But deliver us from ego. For thine is the realm and the power and the glory, for ever. Amen. Group Of Drunks grant me the serenity To accept the things I cannot change, Courage to change the things I can, And wisdom to know the difference. ------------- Group Of Drunks, who art in heaven, Hallowed be thy name. Armageddon can wait, Thy will be done, On earth as it is in heaven. Give us this day our daily bread; And forgive us our trespasses, As we also have forgiven our trespasses; And lead us not into temptation, But deliver us from ego. For thine is the big blue boat and the power and the glory, for ever. +Amen. Group Of Drunks grant me the serenity To accept the things I cannot change, Courage to change the things I can, And wisdom to know the difference. ------------- Elohim, who art in heaven, Hallowed be thy name. Armageddon can wait, Thy will be done, On earth as it is in heaven. Give us this day our daily bread; And forgive us our trespasses, As we also have forgiven our trespasses; And lead us not into temptation, But deliver us from ego. For thine is the Ца&#128;с&#130;во and the power and the glory, + for ever. Amen. Elohim grant me the serenity To accept the things I cannot change, Courage to change the things I can, And wisdom to know the difference. ------------- $
#!/usr/bin/perl -w use 5.011; use Path::Tiny; use utf8; use open OUT => ':utf8'; use Data::Dump; use Text::Template; use POSIX qw(strftime); binmode STDOUT, 'utf8'; my $input = <<'(END INPUT)'; {$God}, who art in heaven, Hallowed be thy name. {$Thy_kingdom_come}, Thy will be done, On earth as it is in heaven. Give us this day our daily bread; And forgive us our trespasses, As we also have forgiven our trespasses; And lead us not into temptation, But deliver us from {$evil}. For thine is the {$kingdom} and the power and the glory, for ever. Ame +n. (END INPUT) my $input2 = <<'(END INPUT2)'; {$God} grant me the serenity To accept the things I cannot change, Courage to change the things I can, And wisdom to know the difference. (END INPUT2) my $path1 = Path::Tiny->cwd; say "path1 is $path1"; say "input is $input"; ## populate hash my $data = [ [ 'God', '(silence)', '&#1041;&#1086;&#1088;&#1080;&#1089;&#1073;&#1086;&#1078;', 'Elohim', 'Group Of Drunks' ], [ 'Thy_kingdom_come', 'Armageddon can wait', 'Ta ti ti ta', 'Let sci +ence be' ], [ 'evil', 'ego', 'your followers', 'being too seri +ous' ], [ 'definite_article', 'the', 'ze', 'die' ], [ 'kingdom', '&#1062;&#1072;&#1088;&#1089;&#1090;&#1074;&#1 +086;', 'realm', 'big blue boat' ] ]; #dd $data; ## main loop # set trials my $trials = 3; my $dummy = 1; my $first_second = strftime( "%d-%m-%Y-%H-%M-%S", localtime ); while ( $trials > 0 ) { # create an output file my $out_file = $path1->child( 'my_data', "$first_second", "$first_second\.$dummy. +txt" ) ->touchpath; say "out_file is $out_file"; my %vars = map { $_->[0], $_->[ rand( $#{$_} ) + 1 ] } @{$data}; my $rvars = \%vars; my $template = Text::Template->new( TYPE => 'STRING', ENCODING => 'U +TF-8', SOURCE => $input ) or die "Couldn't construct template: $!"; my $result = $template->fill_in( HASH => $rvars ); $out_file->append_utf8($result); $out_file->append_utf8("\n"); my $template2 = Text::Template->new( TYPE => 'STRING', ENCODING => ' +UTF-8',SOURCE => $input2 ) or die "Couldn't construct template: $!"; my $result2 = $template2->fill_in( HASH => $rvars ); $out_file->append_utf8($result2); $trials -= 1; $dummy += 1; } # end while condition print "OUTFILES*******************\n"; foreach my $filename ( glob("./my_data/$first_second/*") ) { open my $fh, '<', $filename or die "can't print $filename! $!"; while ( my $line = <$fh> ) { print "$line"; } say "-------------"; close $fh; } __END__

First I wonder how characters go to become cyrillic in the saved files and to mojibake on STDOUT.

Finally, I'd like to take this all in a more perl direction. I'm looking for a way to make better agreement between subject and verb in templates by taking into account whether something is a singular whole or a collection of parts. 'Group of Drunks' would be plural, so the use of "thy" should rather be "your." Can I create a package that could incorporate such considerations along the lines of this syntax:

$T::recipient = 'Josh'; $text = $template->fill_in(PACKAGE => T);

Thanks for your comment,

Replies are listed 'Best First'.
Re^3: making the Vater Unser non-sectarian using Text::Template
by LanX (Saint) on Apr 28, 2019 at 21:33 UTC
    > dein Reich komme;

    LOL, you made my day. :)

    BTW: Swedes have a "Riksdagen" and Dutch a "Rijksmuseum" ...

    > (Reinhold Niebuhr), was a german expat

    according to WP he was born in the US

    But true, collaborations between confessions are very normal here, the Lutheran church next door is used by Ethiopian Christians for Easter mass.

    > German has a lot of theological influence on Americans with most of us being too ignorant to know it.

    BTW: not only among Christians, see Reform_Judaism

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1233092]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-04-25 07:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found