X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=bp_bin%2Fcompute;h=0bcd6ca9fe6bea499411b1dc207bfcbc4a2bd64e;hb=2f0fd91b461033529a4a72e161bd133252a22eb6;hp=359becd34640a9b04859d5f0adc0accecbb4f80e;hpb=5aed4676ad1bf35abbade6215ac90ee591e6d8fe;p=biopieces.git diff --git a/bp_bin/compute b/bp_bin/compute index 359becd..0bcd6ca 100755 --- a/bp_bin/compute +++ b/bp_bin/compute @@ -26,7 +26,9 @@ # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< +use warnings; use strict; +use Data::Dumper; use Maasha::Common; use Maasha::Biopieces; @@ -38,7 +40,8 @@ my ( $options, $in, $out, $record, $eval_key, @keys, $eval_val ); $options = Maasha::Biopieces::parse_options( [ - { long => 'eval', short => 'e', type => 'string', mandatory => 'yes', default => undef, allowed => undef, disallowed => undef }, + { long => 'eval', short => 'e', type => 'string', mandatory => 'yes', default => undef, allowed => undef, disallowed => undef }, + { long => 'format', short => 'f', type => 'string', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, ] ); @@ -61,8 +64,16 @@ while ( $record = Maasha::Biopieces::get_record( $in ) ) map { $eval_val =~ s/\Q$_\E/$record->{ $_ }/g } @keys; - $record->{ $eval_key } = eval "$eval_val"; - Maasha::Common::error( qq(eval "$eval_key = $eval_val" failed -> $@) ) if $@; + if ( $eval_val =~ /\+|\-|\*|\// or $eval_val =~ /\s+x\s+/) + { + $record->{ $eval_key } = eval "$eval_val"; + Maasha::Common::error( qq(eval "$eval_key = $eval_val" failed -> $@) ) if $@; + $record->{ $eval_key } = sprintf( $options->{ 'format' }, $record->{ $eval_key } ) if $options->{ 'format' }; + } + else + { + $record->{ $eval_key } = $eval_val; + } } else {