#! /usr/bin/perl =start comment replace special LaTeX-characters in $text! this are: # $ % & ~ _ ^ \ { } =end comment =cut use warnings; use strict; my $date_old = "Samstag, 25.05.2013 "; #my @special_characters = q/# $ % & ~ _ ^ \ { }/; while( ) { if (/^"([^"]{2,})","(\d)","(.+)"$/) { chomp; my $date_time = $1; my $who = $2; my $text = $3; # my $first = q'&'; # my $second = q'%'; # my $third = q'~'; # my $fourth = q'$'; # my @special_characters = ($first, $second, $third, $fourth); my @special_characters = q{# $ % & ~ _ \\ { } ^}; foreach my $i (@special_characters) { $text =~ s/$special_characters[$i]/\\$&/g; } # $text =~ s![#$%&~_}{^]!\\$&!g; my ($date_new) = $date_time =~ /^([a-z]+, \d\d\.\d\d\.\d{4} )/i; # $date_time = ($date_new eq $date_old) ? ($date_time) =~ s/$date_old// : $date_time; if ($date_new eq $date_old) { $date_time =~ s/$date_old// } $date_old = $date_new; $who = ($who == 1) ? '\maaki ' : '\puh '; # print $out $_; print "\\datum{$date_time}\n\n$who $text\n\n"; } else {next;} } __DATA__ "Sonntag, 26.05.2013 - 13:13:27","0","Lieber Herr % , & text text with some %special characters" "Sonntag, 26.05.2013 - 13:35:47","1","Sehr gerne! ^ _~}# and here some other characters" "Sonntag, 26.05.2013 - 13:49:15","0",":-))" "Mittwoch, 05.06.2013 - 18:12:09","0","Besten Dank, & hat prima geklappt. {Greetings!}" "Mittwoch, 05.06.2013 - 19:16:47","1","% _ text text!" "Mittwoch, 05.06.2013 - 19:17:30","0","~Prima! #Danke!!" "Samstag, 08.06.2013 - 09:21:09","1","_ 10. Jul Text text %" "Samstag, 08.06.2013 - 10:08:45","0","Ja, osaka ffm lh 741 & ffm muc lh 114 abflug 16:00"