diff options
-rw-r--r-- | Perl/Zinc/TraceUtils.pm | 15 | ||||
-rw-r--r-- | Perl/t/traceutils.t | 7 |
2 files changed, 15 insertions, 7 deletions
diff --git a/Perl/Zinc/TraceUtils.pm b/Perl/Zinc/TraceUtils.pm index 8a3bc76..95327ce 100644 --- a/Perl/Zinc/TraceUtils.pm +++ b/Perl/Zinc/TraceUtils.pm @@ -42,11 +42,16 @@ sub Item { return "'$value'"; } elsif ($ref eq '') { # scalar if (defined $value) { - if ($value =~ /^-?\d+(\.\d*(e[+-]?\d+)?)?$/ or # -1. or 1.0 - $value =~ /^-[a-zA-Z]([\w])*$/ # -option1 or -option-1 - ) { - return $value; - } elsif ($value eq '' + if ($value =~ /^-[a-zA-Z]([\w])*$/) { # -option1 or -option-1 + return $value; + } elsif ($value =~ /^-?\d+(\.\d*(e[+-]?\d+)?)?$/) { # -1. or 1.0 or -1.2e+22 or 1.02e+034 + if ($value =~ /(.*[-+]e)0+(\d+)/) { # removing the 0 after e+ or e- + return $1.$2; + } else { + return $value; + } + } + } elsif ($value eq '' or $value =~ /\s/ or $value =~ /^[a-zA-Z]/ or $value =~ /^[\W]/ diff --git a/Perl/t/traceutils.t b/Perl/t/traceutils.t index 0636037..4d35ae6 100644 --- a/Perl/t/traceutils.t +++ b/Perl/t/traceutils.t @@ -1,7 +1,7 @@ #!/usr/bin/perl -w # -# $Id: traceutils.t,v 1.2 2004-05-07 16:53:43 mertz Exp $ +# $Id: traceutils.t,v 1.3 2005-06-23 17:09:49 mertz Exp $ # Author: Christophe Mertz # @@ -65,9 +65,12 @@ $arg = "(-1, -2, -3, -4)"; is (&List (eval $arg), $arg, $arg); $arg = "(1.2, -2, .01, -1.2e+22, 1.02e+34)"; - is (&List (eval $arg), ($arg =~ s/\.01/0.01/ , $arg ), $arg); +$arg = "(1.2, -2, .01, -1.2e+022, 1.02e+034)"; +my $correctedArg = "(1.2, -2, 0.01, -1.2e+22, 1.02e+34)"; +is (&List (eval $arg), $correctedArg, $arg); + $arg = "('-1aa' => -2, '-a b', -1.2)"; is (&List (eval $arg), $arg, $arg); |