# 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: => /categories/programming/ Programming => /categories/writing/ Writing Tags: => /tags/perl/ Perl # Footer Below are various useful links within this site and to related sites (not all have been converted over to Gemini). => /now/ Now => /contact/ Contact => /bio/ Biography => /bibliography/ Bibliography => /support/ Support => /fiction/ Fiction => //fedran.com/ Fedran => https://mfgames.com/ Coding => https://moonfire.us/ The Moonfires => /categories/ Categories => /tags/ Tags => /privacy/ Privacy => /colophon/ Colophon => /license/ License => https://lists.typewriter.press/subscription?f=RDQ6f3AFHXnX2o763d5TgUmaYP7N763gR6FjZyGUUFWhyRkpgZF9I35ySICDBEdFFtgG Mailing List => https://d.moonfire.us/blog/2012/05/01/an-obsession-with-data-a-k-a-writers-write/