Skip to content

Instantly share code, notes, and snippets.

@natpen
Created September 20, 2016 02:01
Show Gist options
  • Save natpen/a7afe923bc31ec69682c6a8c5ed80207 to your computer and use it in GitHub Desktop.
Save natpen/a7afe923bc31ec69682c6a8c5ed80207 to your computer and use it in GitHub Desktop.
Quick and dirty perl script I wrote to compose a bunch of game artifact PDFs. Some have "repeat me" modifiers in the filename, which this respects. The goal is just an easily-printable pdf to take to the neighborhood printing shop.
#!/usr/bin/env perl
use strict;
use warnings;
# NOTE: have to use absolute dirpath for ARGV[0] for now
use IO::Dir;
use File::Basename;
my $pdfjoin_input_args = "";
my $pdfjoin_output_file = dirname($ARGV[0]) . "/" . basename($ARGV[0]) . ".pdf";
my @game_files;
my $game_dir = $ARGV[0];
tie my %dir, 'IO::Dir', $game_dir;
GAME_FILE: foreach (keys %dir) {
next GAME_FILE if $_ eq "." || $_ eq "..";
my $game_file = $game_dir . "/" . $_;
(my $repetitions) = ($_ =~ /\[(\d+)\]/);
foreach (1..$repetitions // 1) {
$pdfjoin_input_args = $pdfjoin_input_args . " " . $game_file;
push @game_files, $game_file;
}
}
system("pdfjoin", "-o", $pdfjoin_output_file, @game_files);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment