1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# #!perl
use utf8;
my $Path = 'C:\\Programme\\Application\\Session';
my $iniFile = 'application.ini';
# read ini
my $conf = &iniRead ( $Path . "\\" . $iniFile);
# write ini
&iniWrite ( $Path . "application.bkp", $conf);
# - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - #
#
# Subs Subs Subs Subs Subs Subs
#
# - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - # - #
sub iniRead {
my $ini = $_[0];
my $conf;
open (INI, '<:raw:encoding(UTF-16LE):crlf', $ini) or die "Kann File $ini nicht zum lesen oeffnen: $!\n";
while (<INI>) {
chomp;
# non printable ascii chars -> [^ -~]*
if (/^[^ -~]*\[(.*?)\]$/) {
$section = $1;
}
if ( /^(.*?)\=(.*?)$/ ) {
$conf->{$section}->{$1} = $2;
}
}
close (INI);
return $conf;
}
sub iniWrite {
my $ini = $_[0];
my $conf = $_[1];
my $contents = '';
foreach my $section ( sort { (($b eq '_') <=> ($a eq '_')) || ($a cmp $b) } keys %$conf ) {
my $block = $conf->{$section};
$contents .= "\n" if length $contents;
$contents .= "[$section]\n" unless $section eq '_';
foreach my $property ( sort keys %$block ) {
$contents .= "$property=$block->{$property}\n";
# print "$property=$block->{$property}\n";
}
}
open( CONF,'>:raw:encoding(UTF-16LE):crlf', $ini ) or die "Kann File $ini nicht zum schreiben oeffnen: $!\n";
print CONF $contents;
close CONF;
}
C:\Users\appUser1> perl -pe "BEGIN { binmode $_, ':raw:encoding(UTF-16LE)' for *STDIN, *STDOUT };" <application.ini >application.bkp
print CONF "\N{BYTE ORDER MARK}";