tzstripper.pl
#!/usr/bin/perl
# populate an array with the search strings
@tz = ("DTEND", "EXDATE", "DTSTART");
#open source ical file
open (calendar, "TBC Calendar.ics") or die "I couldn't open it";
#open temp file to write to
open (test, ">test.dat");
#do this for every line in the calendar file
for $line () {
$n = 5; # starting number of characters to search for
$p = 0; # starting position in search array
until ($n == 8)
{
$first = substr($line, 0, $n); # take the first 'n' characters and dump them into a scalar
if ($first eq $tz[$p]) # if the first ‘n’ characters match a search term from ‘tz’
{
@spl = split(/;/, $line); # split the line at the semi-colon
if (substr($spl[1], 0, 4) eq ‘TZID’) # if the beginning of the second half of the split matches TZID
{
substr($spl[1], 0, 45) = “”; # strip faulty timezone info
$line = join(”, @spl); # merge the two halves
}
else # if TZID wasn’t in the line
{
$line = join(’;', @spl); #just join them back
}
}
$n++; # increment the number of characters we are comparing
$p++; # move on to the next search term
}
print test $line; # output the line to the temp file
}
close calendar; close test; # close the files we are using
open (test, “test.dat”); open (calendar, “>TBC Calendar.ics”); # reopen files
for $line () # parsing through the temp file again
{
print calendar $line; # writing the temp file to the calendar
}
close calendar; close test; #close the files one last time





