From 17d9443ee8d459794d90e4c38b04ba6ca4a93c3b Mon Sep 17 00:00:00 2001 From: dakkar Date: Fri, 5 Aug 2016 12:01:12 +0100 Subject: allow symbols on the command line --- dobble.pl | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'dobble.pl') diff --git a/dobble.pl b/dobble.pl index 5040d7a..324b3cd 100755 --- a/dobble.pl +++ b/dobble.pl @@ -124,8 +124,14 @@ package CardsTable { sub load_symbols($file) { return undef unless $file; - use Path::Tiny; - return [ path($file)->lines_utf8 ]; + require Path::Tiny; + return [ Path::Tiny::path($file)->lines_utf8 ]; +} + +sub split_symbols($string) { + return undef unless $string; + require Encode; + return [ split //, Encode::decode('utf-8',$string) ]; } use Getopt::Long::Descriptive; @@ -134,7 +140,8 @@ my ($opt,$usage) = describe_options( '%c %o', [ 'order|o=i', 'order of the finite field', { required => 1 } ], [ 'padding|p!', 'vertically align symbols', { default => 0 } ], - [ 'symbols|s=s', 'file with one symbol per line' ], + [ 'symbols|s=s', 'string of symbols (one per character)' ], + [ 'symbols-from|f=s', 'file with one symbol per line' ], [], ['help|h', 'show this help text', { shortcircuit => 1 } ], ); @@ -144,7 +151,10 @@ my $order = $opt->order; my $plane = FiniteProjectivePlane->new(mod=>$order); my $table = CardsTable->new( padding=>$opt->padding, - symbols => load_symbols($opt->symbols), + symbols => ( + split_symbols($opt->symbols) + || load_symbols($opt->symbols_from), + ), ); # sanity check -- cgit v1.2.3