DO NOT RUN THIS PROGRAM use strict; use warnings; use LWP::Simple; use HTML::TreeBuilder; use HTML::FormatText; my $URL= get("https://www.events.utoronto.ca/iCal.php?ical=1&campus=0&sponsor%5B%5D=&audience%5B%5D=&category%5B%5D="); my $Format=HTML::FormatText->new; my $TreeBuilder=HTML::TreeBuilder->new; $TreeBuilder->parse($URL); my $Parsed=$Format->format($TreeBuilder); open(FILE, ">UOTSUMMER.txt"); print FILE "$Parsed"; close (FILE); open (FILE, "UOTSUMMER.txt"); my @array=; my $string ="@array"; my $offset = 0; # Where are we in the string? my $numResults = 0; while (1) { my $idxSummary = index($string, "SUMMARY", $offset); my $result = ""; my $idxDescription = index ($string, "DESCRIPTION", $offset); my $result2= ""; if ($idxSummary > -1) { $offset = $idxSummary + length("SUMMARY"); my $idxDescription = index($string, "DESCRIPTION", $offset); if ($idxDescription == -1) { print "(Data malformed: missing DESCRIPTION line.)\n"; last; } if ($idxDescription > -1) { $offset = $idxDescription+ length("DESCRIPTION"); my $idxLocation= index($string, "LOCATION", $offset); if ($idxLocation == -1) { print "(Data malformed: missing LOCATION line.)\n"; last; } my $length = $idxDescription - $offset; my $length2= $idxLocation - $offset; $result = substr($string, $offset, $length); $result2= substr ($string, $offset, $length2); $offset = $idxDescription + length("DESCRIPTION"); $result =~ s/^\s+|\s+$//g ; # Strip leading and trailing white #+space, $result2 =~ s/^\s+|\s+$//g ; # includng newlines. $numResults++; } else { print "(All done. $numResults result(s) found.)\n"; last; } open (FILE2, "UOT123.txt") print FILE2 "TITLE: <$result>\n DESCRIPTION: <$result2>\n";