Hello all!

First question here in this forum. I am seeking wisdom but I am feeling bad, because this question seems to be obvious. But nevertheless I need your help:

Here a code snippet to illustrate my attempt: How to escape special characters with \ for a LaTeX file (this are: # $ % & ~ _ ^ \ { })

I would be grateful for any hint
Thank you!
marek

#! /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( <DATA> ) { 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/$d +ate_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 geklap +pt. {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 l +h 114 abflug 16:00"

In reply to Escape special characters for a LaTeX file by marek1703

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.