Hello, I have a dilemma involving updating a build number in a .rc2 file. I have other scripts that update the build number fine, but this one is different as I need the number to always remain 4 digits. The lines involving the build number are:

VALUE "FileVersion", "0001.0000.0000.0001\0"

VALUE "ProductVersion", "0001.0000.0000.0001\0"

I need to bump up the last number in the last set of numbers, i.e. the first build would bump .0001\0" to .0002\0". I know how to do that. My problem occurs because that last set of numbers, .0001, needs to always remain 4 digits, never more. So for example build number 10 would need to look like:

VALUE "FileVersion", "0001.0000.0000.0010\0"

VALUE "ProductVersion", "0001.0000.0000.0010\0"

For my other builds, it's easy, there is no restriction on the number of digits. For example I do the following (sorry if the code isn't the most efficient, I'm fairly new to Perl):
## This is the line containing the build num from the file $buildnumfi +le2. ## [assembly: AssemblyFileVersion("1.0.0.408")] ### Opens the buildnum file for input. tie @array2, 'Tie::File', $buildnumfile2 or die "Cannot open build number file: $!"; $num_files = @array2; for ($p=0; $p<$num_files; $p++) { $file = $array2[$p]; if ($file =~ /(AssemblyFileVersion)\(("([^"]*)")\)\]/) { $relnumber2 = $3; #1.0.0.1 @nums2 = split /\./, $relnumber2; $lastbldnumber2 = $nums2[3]; $newbldnumber2 = $lastbldnumber2 + 1; } } ### Now replace the old build number with the new build number. for (@array2) { s/(AssemblyFileVersion)(\("$nums2[0]\.$nums2[1]\.$nums2[2]\.$lastbld +number2"\))/AssemblyFileVersion\("$nums2[0]\.$nums2[1]\.$nums2[2]\.$n +ewbldnumber2"\)/g; } $newrelnumber2 = join ".", $nums2[0], $nums2[1], $nums2[2], $newbldnum +ber2;
TIA for your help! Any advice is greatly appreciated.

In reply to increment # but keep # of digits same by yankeeblue

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.