This page permanently redirects to gemini://d.moonfire.us/blog/2012/05/01/an-obsession-with-data-a-k-a-writers-write/.

An obsession with data (a.k.a. "writers write")

=> Up a Level

Setup

Directives

use strict; use warnings;

Go through all the files in the directory from the first argument.

my %months = (); my $total = 0;

open FIND, “find ‘$ARGV[0]’ -type f -name ‘*.txt’ |” or die "Cannot open find ($!)";

while () { chomp; my $file = $_;

# Make sure the file has a date field.
my $sep = $/;
$/ = undef;
open FILE, "<$file";
$_ = ;
close FILE;
$/ = $sep;

next unless ($_ =~ m@* Date: (d+)-(d+)-d+@);

my $year = $1;
my $month = $2;

# Figure out how many words.
my $word_output = `wc -w "$file"`;

next unless $word_output =~ m@^s*(d+)s+@s;

my $words = $1;

# Print the file.
print STDERR "Processing $file ($year-$month) [$words]n";

my $key = "$year-$month";

$months{$key} += $words;
$total += $words;

}

close FIND;

Add in the zeros.

foreach my $y (qw(2007 2008 2009 2010 2011)) { foreach my $m (qw(01 02 03 04 05 06 07 08 09 10 11 12)) { $months{"$y-$m"} += 0; } }

Write out the months and dates.

foreach my $mkey (sort(keys(%months))) { my $words = $months{$mkey};

print "$mkeyt$wordsn";

}

print “nTotalt$totaln”;

Metadata

Categories:

=> Programming | Writing

Tags:

=> Perl

Footer

Below are various useful links within this site and to related sites (not all have been converted over to Gemini).

=> Now | Contact | Biography | Bibliography | Support

=> Fiction | Fedran | Coding | The Moonfires

=> Categories | Tags

=> Privacy | Colophon | License

=> Mailing List

=> https://d.moonfire.us/blog/2012/05/01/an-obsession-with-data-a-k-a-writers-write/

Proxy Information
Original URL
gemini://d.moonfire.us/blog/2012/05/01/an-obsession-with-data-a-k-a-writers-write
Status Code
Success (20)
Meta
text/gemini;lang=en-US
Capsule Response Time
816.015625 milliseconds
Gemini-to-HTML Time
1.08569 milliseconds

This content has been proxied by September (3851b).