Create a gist now

Instantly share code, notes, and snippets.

@xjackk /
Last active Aug 29, 2015

What would you like to do?
The Diary of Anne Frank

The Diary of Anne Frank

I am going to be doing some light reading this weekend. I wrote a script that generates a markdown copy of "The Diary of Anne Frank", a classic.


To install the book simply run.


This will generate a file in the same directory.

~ Enjoy!

#!/usr/bin/env perl
use warnings;
use strict;
use LWP::Simple;
use HTML::WikiConverter;
use HTML::WikiConverter::Markdown;
## One time download for reading.
## - xjrK
## "The Diary of Anne Frank"
# grab pages and get to reading this weekend.
my ($page1, $page2, $page3, $page4, $page5);
$page1 = get("");
$page2 = get("");
$page3 = get("");
$page4 = get("");
$page5 = get("");
my @pages = ($page1, $page2, $page3, $page4, $page5);
# open the diary.
# "The only girl I've ever loved was born with roses in her eyes"
my $diaryfile = "";
unless(open DIARY, '>>'.$diaryfile) { die "Can't write to it!"; }
foreach my $page (@pages) {
my $converter = new HTML::WikiConverter( dialect => 'Markdown' );
# Append to file
print DIARY $converter->html2wiki($page);
# close the diary
close DIARY;
# "But then they buried her alive one evening, 1945, with just her sister at her side
my $data = read_file($diaryfile);
# Clean everything up. (=
# "God is a place; You will wait for the rest of your life."
$data =~ s/\<br \/>//gi;
$data =~ s/\<table>//gi;
$data =~ s/\<\/table//gi;
$data =~ s/\<br \///gi;
$data =~ s/\<tr>\///gi;
$data =~ s/\<\/tr>\///gi;
$data =~ s/<tr>//gi;
$data =~ s/\<\/tr>//gi;
$data =~ s/<td>//gi;
$data =~ s/<\/td>//gi;
$data =~ s/\s\\_//gi;
$data =~ s/\\_\w//gi;
$data =~ s/\w\\_//gi;
$data =~ s/!\\_//gi;
write_file($diaryfile, $data);
exit; # all done.
# read some stuff
sub read_file {
my ($filename) = @_;
open my $in, '<:encoding(UTF-8)', $filename or die "Could not open '$filename' for reading $!";
# "In my dreams you're alive and you're crying"
local $/ = undef;
my $all = <$in>;
close $in;
return $all;
# write some stuff to the file
sub write_file {
my ($filename, $content) = @_;
open my $out, '>:encoding(UTF-8)', $filename or die "Could not open '$filename' for writing $!";
# "Rings of flowers around your eyes,
# And I'll love you for the rest of your life when you're ready
print $out $content;
close $out;
# Install the goods.
use strict;
use warnings;
# quick and dirty for the linux box. Sorry about it.
system("cpan", "HTML::WikiConverter");
system("cpan", "HTML::WikiConverter::Markdown");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment