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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.