From 8d4c9e894db63b43e54153e48b85ed220b34f823 Mon Sep 17 00:00:00 2001 From: Lawrence Siebert Date: Wed, 11 Sep 2013 05:44:40 -0700 Subject: [PATCH 1/2] added comma|c option allowing the ability to specify a delimiter for input values other than \n --- bin/st | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/bin/st b/bin/st index 7e1aaa1..02751a8 100755 --- a/bin/st +++ b/bin/st @@ -30,6 +30,9 @@ GetOptions( 'complete|all', 'default|basic', + # input control + 'comma|c=s', + # output control 'delimiter|d=s', 'format|fmt|f=s', @@ -48,7 +51,6 @@ pod2usage(1) if $opt{help}; my %config = get_config(%opt); my %result = process(%opt); - my @opt = grep { defined $result{$_} } statistical_options(%opt); if (scalar @opt == 1) { @@ -119,8 +121,30 @@ sub process { my $M2 = 0; # used to calculate variance - - while (my $num = <>) { +my $inputdelimiter = $opt{'comma'}; +my @element_arr; +my $interator; + if ($inputdelimiter) { + $interator = sub { + unless (scalar @element_arr) { + my $line = <>; + if ($line ne '') { + @element_arr = split($inputdelimiter , $line); + } + else { return 0; } #if no line done with all files + } + my $element = pop @element_arr; + $element =~ s/^\s+//; + $element =~ s/\s+$//; + return $element; + } + } + else { + $interator = sub { my $line = <>; return $line; } + } + + + while (my $num = $interator->()) { chomp $num; if (!valid_input($num)) { @@ -314,6 +338,10 @@ If no functions are selected, C will print: n min max sum mean sd +=head3 INPUT FORMATTING + + --comma|-c= #default: "\n" + =head3 FORMATTING --delimiter|d= # default: "\t" From a413f6b7872208b86ae505f422da7734f684337f Mon Sep 17 00:00:00 2001 From: Lawrence Siebert Date: Wed, 11 Sep 2013 21:02:25 -0700 Subject: [PATCH 2/2] line now tests for true, and we now look at items in the correct order --- bin/st | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bin/st b/bin/st index 02751a8..7c3c87e 100755 --- a/bin/st +++ b/bin/st @@ -124,16 +124,17 @@ sub process { my $inputdelimiter = $opt{'comma'}; my @element_arr; my $interator; + if ($inputdelimiter) { $interator = sub { unless (scalar @element_arr) { my $line = <>; - if ($line ne '') { + if ($line) { @element_arr = split($inputdelimiter , $line); } else { return 0; } #if no line done with all files } - my $element = pop @element_arr; + my $element = shift @element_arr; $element =~ s/^\s+//; $element =~ s/\s+$//; return $element;