Greetings great monks.
I need to compare 2 revision numbers to see if they are the same. The difficulty is that "*" are used as wildcards. The terminology used is major_number.minor_number. My code worked just fine until people started using wildcards for minor numbers
Example: Rev1 | Rev2 | Result | 02.10 | 02.10 | Equal | 2.1 | 02.10 | Equal | 02.10 | * | Equal | 02.10 | 02.* | Equal |
I believe that astrisks will only be used for minor numbers (wouldnt make sense for major). Thanks.
Update: I included the code I tried to solve the problem. The issue is handling wildcards and empty strings
sub rev_compare() { #Args: 2 rev strings the section rev first and the master rev second #Returns a 1 if they match and a 0 if they do not #this sub takes 2 REV strings and compares them my $section_raw_rev_string = shift; my $main_raw_rev_string = shift; my $main_major_number = ""; my $main_minor_number = ""; my $section_major_number = ""; my $section_minor_number = ""; if ($section_raw_rev_string eq "*") { return 1; } if ($main_raw_rev_string =~ /(.+)\.(.+)/) { $main_major_number = $1; $main_minor_number = $2; } if ($section_raw_rev_string =~ /(.+)\.(.+)/) { $section_major_number = $1; $section_minor_number = $2; } if ($main_raw_rev_string eq $section_raw_rev_string) { return 1; } if ($section_raw_rev_string eq "*") { return 1; } if ($section_major_number == $main_minor_number) { if ($section_minor_number eq "*") { return 1; } if ($section_minor_number == $main_minor_number) { return 1; } } return 0; }
Update: I located the offending code (if ($section_major_number == $main_minor_number) The $main_minor_number should have been $main_major_number. If there is a better way to do this please let me know because it feels like a hacked together jury-rigged piece of crap
In reply to Comparing revision numbers by zek152
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |