# #!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 () { 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; }