...
Post
URL
The title
The blog post goes here
Comment
URL
The title of the comment
The content itself
...
####
my $tmpComments = File::Temp->new(SUFFIX=>'.txt') or die "File::Temp: $!\n";
foreach (#Go through the whole xml file) {
if ($type eq 'Comment') {
# Parse the xml and save the parts as variables
print $tmpComments "$posturl~~~$date~~~$author~~~$content\n";
# $posturl holds the url
}
}
####
foreach (#Loop through the xml file again) {
print "$title\n";
print "$content\n";
...
seek $tmpComments, 0, 0 or die "Seek $tmpComments failed: $!\n"; #Rewind temporary comments file
while (my $line = <$tmpComments>) {
# Split each line, store url as $commentID
my @process_comment = split(/~~~/, $line);
my $commentID = $process_comment[0];
# If the urls match, add it to the comments variable
if ($commentID eq $posturl) {
my $commentDate = $process_comment[1];
my $commentAuthor = $process_comment[2];
my $commentBody = $process_comment[3];
$comments.= "$commentDate | $commentAuthor | $commentBody";
}
}
print $comments;
}