ICS Calendar Files: CRLF? WTF?
According to section 3.1 of RFC 5545
the content lines should end with CRLF. As a FreeBSD user, I am not
used to ending of a line with two characters. Perl command 'chomp'
does not remove the carriage return character. I've noticed it after
I'd decided to print debug messages to a file and view it with 'less'
when I so an extraneous '^M' at the end of values.
When printed by the program, shortened lines are seen without preceding
text. Why? Because that carriage return characters make the type writer
go back to the beginning of the line.
BTW, the escape sequence for the CR character is "\r".
Perl provides the coder with a built-in variable named "$/" which
defines the characters to be removed from the end of a line.
So, I added to the code the following command:
$/ = "\r\n";
I've noticed that the ICS files contain escape sequences, such as
'\n' in the lines, so I need somehow to translate them into their
values. A usefule module to do it is String::Escape. I use the function
'unbackslash' to translate escape seequences into character values, so
'\n' becomes a newline. To use that function I add:
use String::Escape qw(unbackslash);
Modules can be obtained using cpan as follows:
% cpan String::Escape