in reply to Re^5: Begginer's question: If loops one after the other. Is that code correct?
in thread Begginer's question: If loops one after the other. Is that code correct?
Also, I used XML::LibXML to parse the structure.
#!/usr/bin/perl use warnings; use strict; use utf8; use XML::LibXML; my $file = shift; my %to_cyrilic = ( # Insert the hash definition here, see below. ); my $regex = join '|', sort { length $b <=> length $a } keys %to_cyrili +c; my $dom = 'XML::LibXML'->load_html( location => $file ); for my $text ($dom->findnodes('//text()')) { my $etext = $text; $text->setData($etext) if $etext =~ s/($regex)/$to_cyrilic{$1}/g; } print $dom;
Note that PRE tags preserve non-latin1 characters.
F => 'Ф',
H => 'Х',
N => ':',
Nj => 'Њ',
b => 'б',
c => 'ц',
d => 'д',
e => 'e',
h => 'х',
i => 'и',
l => 'л',
m => 'м',
n => 'н',
nj => 'њ',
p => 'п',
r => 'р',
s => 'с',
t => 'т',
u => 'у',
v => 'в',
z => 'з',
ć => 'ћ',
Č => 'Ч',
č => 'ч',
Đ => 'Ђ',
đ => 'ђ',
Š => 'Ш',
š => 'ш',
Ž => 'Ж',
ž => 'ж',
# etc., this is enough to run the example.
($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^7: Begginer's question: If loops one after the other. Is that code correct?
by predrag (Scribe) on Jan 11, 2017 at 19:36 UTC | |
by choroba (Cardinal) on Jan 11, 2017 at 20:47 UTC | |
by predrag (Scribe) on Jan 12, 2017 at 15:05 UTC | |
by choroba (Cardinal) on Jan 12, 2017 at 15:10 UTC | |
by predrag (Scribe) on Jan 12, 2017 at 15:29 UTC |