<commit_before>#!/usr/bin/env perl
use v5.10;
use strict;
use warnings;
use File::Basename qw/fileparse/;
use File::Spec;
use File::stat;

unless (@ARGV) {
    die "Usage: $0 <file|directory> [file|directory] ...\n";
}

for my $arg (@ARGV) {
    if ( -f $arg ) {
        _build_go($arg);
    }
    elsif ( -d $arg ) {
        _build_go($_) for map { File::Spec->canonpath($_) } <$arg/*.go>;
    }
    else {
        warn "unknown: $arg\n";
    }
}

sub _build_go {
    my $src = shift;
    unless ( -f $src ) {
        warn "unknown: $src";
        return;
    }
    unless ( -d 'bin' ) {
        mkdir 'bin';
    }
    my $bin = "bin/" . fileparse( $src, qr/\.go/ );
    if ( -f $bin && stat($bin)->mtime > stat($src)->mtime ) {
        say "$bin up to date";
    }
    else {
        my $cmd = "go build -o $bin $src";
        say($cmd);
        system($cmd);
    }
}
<commit_msg>default to building all chapters; add verbose option<commit_after>#!/usr/bin/env perl
use v5.10;
use strict;
use warnings;
use File::Basename qw/fileparse/;
use File::Spec;
use File::stat;
use Getopt::Long;

my $verbose;
GetOptions( "verbose|v" => \$verbose ) or die("Error in command line arguments\n");

unless (@ARGV) {
    @ARGV = <./ch*>;
}

for my $arg (@ARGV) {
    if ( -f $arg ) {
        _build_go($arg);
    }
    elsif ( -d $arg ) {
        _build_go($_) for map { File::Spec->canonpath($_) } <$arg/*.go>;
    }
    else {
        warn "unknown: $arg\n";
    }
}

sub _build_go {
    my $src = shift;
    unless ( -f $src ) {
        warn "unknown: $src";
        return;
    }
    unless ( -d 'bin' ) {
        mkdir 'bin';
    }
    my $bin = "bin/" . fileparse( $src, qr/\.go/ );
    if ( -f $bin && stat($bin)->mtime > stat($src)->mtime ) {
        say "$bin up to date" if $verbose;
    }
    else {
        my $cmd = "go build -o $bin $src";
        say($cmd);
        system($cmd);
    }
}

{'fraction_non_alphanumeric': 0.1930195663670016, 'fraction_numerical': 0.0037017451084082496, 'mean_word_length': 1.9984152139461173, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2581062', 'n_tokens_mistral': 735, 'n_tokens_neox': 724, 'n_words': 190}