diff options
| author | Ysmael Ebreo <Ysmael.Ebreo@latticesemi.com> | 2020-04-30 13:55:59 +0800 |
|---|---|---|
| committer | Ysmael Ebreo <Ysmael.Ebreo@latticesemi.com> | 2020-04-30 13:55:59 +0800 |
| commit | 961efa947e1fa63674ea3e4dd930920d18dc0811 (patch) | |
| tree | 668a43d2689734f33d1eb19b3e4337766bfbdec7 | |
| parent | c70b24cc54f3f4faedbbb7105b7844f8cc3294cc (diff) | |
| download | perlweeklychallenge-club-961efa947e1fa63674ea3e4dd930920d18dc0811.tar.gz perlweeklychallenge-club-961efa947e1fa63674ea3e4dd930920d18dc0811.tar.bz2 perlweeklychallenge-club-961efa947e1fa63674ea3e4dd930920d18dc0811.zip | |
Fixed some bugs + Added some test case
| -rw-r--r-- | challenge-058/yet-ebreo/perl/ch-1.pl | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/challenge-058/yet-ebreo/perl/ch-1.pl b/challenge-058/yet-ebreo/perl/ch-1.pl index 7aa7c804ae..2a305c4b8b 100644 --- a/challenge-058/yet-ebreo/perl/ch-1.pl +++ b/challenge-058/yet-ebreo/perl/ch-1.pl @@ -4,20 +4,20 @@ use warnings; use feature 'say'; sub compare { - $_[0] =~ s/[._]0+$//r =~s/_/!/gr =~ s/\d+/0|$&/gre - cmp - $_[1] =~ s/[._]0+$//r =~s/_/!/gr =~ s/\d+/0|$&/gre; + 0+eval "@_"=~s/\S+/\"$&\"/gr =~s/ / cmp /r =~ s/[._]0+\"/\"/gr =~s/_/!/gr =~ s/\d+/sprintf "%09d",$&/gre; } -my @num_set = ( - [qw(0.1 1.1)], - [qw(2.0 1.2)], +my @num_set = ( + [qw(0.1 1.1)], + [qw(2.0 1.2)], [qw(1.2 1.2_5)], [qw(1.2.1 1.2_1)], [qw(1.2.1 1.2.1)], - [qw(3_3 3.3)], + [qw(3_3 3.3)], [qw(1.01.1 1.1.1)], - [qw(2_0 2.0)], + [qw(2_0 2.0)], + [qw(1.9 1.10)], + [qw(1.002 1.2)] ); #Notes: @@ -25,7 +25,7 @@ my @num_set = ( # - 2_00 , 2.0 and 2 are considered equal for my $num (@num_set) { my $c = compare(@{$num}); - printf "%10s %s %-10s %2s\n", $num->[0], qw(< = >)[$c+1], $num->[1], $c ; + printf "%10s %s %-10s %2s\n", $num->[0], qw(< = >)[$c+1], $num->[1], $c; } =begin @@ -38,4 +38,6 @@ perl .\ch-1.pl 3_3 < 3.3 -1 1.01.1 = 1.1.1 0 2_0 = 2.0 0 + 1.9 < 1.10 -1 + 1.002 = 1.2 0 =cut
\ No newline at end of file |
