#!/usr/bin/perl -w use strict; use Getopt::Std; my %opt; getopts('hsS', \%opt); if ($opt{'h'}) { print_usage_and_exit(); } my $file = shift or print_usage_and_exit(); my $numcards = 0; my $in_sideboard = 0; open (DECK, '<:encoding(UTF-8)', $file) or die "Couldn't open $file"; while () { s/^\x{FEFF}//g; # strip UTF-8 byte order mark $in_sideboard = 1 if /^Sideboard/; last if ($opt{'s'} && $in_sideboard); next if ($opt{'S'} && !$in_sideboard); if (/^([0-9]+)/) { $numcards += int($1); } } close (DECK); print $numcards, "\n"; sub print_usage_and_exit { print "Usage: $0 [-hsS] \n"; print " -h: Read this help text\n"; print " -s: Don't include the sideboard in the count\n"; print " -S: ONLY include the sideboard in the count\n"; exit; }