title: Increment variables in files
body: <p>I am a complete rookie with Perl. What I am trying to do is to open a list of files, increment three different variables in each file, save the files, and close.</p>
  
  <p>The variables look like this</p>
  
  <pre><code>This_Is_My_Variable03
  This_Is_My_Variable02
  This_Is_My_Variable01
  </code></pre>
  
  <p>The variable ending in 01 is in the file multiple times.  The variables are at times part of a Character string.  the <code>This_Is_My_Variable</code> part of the variable never changes.</p>
  
  <p>Thanks.</p>
  
  <p>This may not be the best solution but it works</p>
  
  <pre><code>#!perl=C:\IBM\RationalSDLC\ClearCase\bin\perl
  
  use warnings;
  use strict;
  
  use Tie::File;
  
  tie my @data, 'Tie::File', 'myfile.txt' or die $!;
  
  s/(This_Is_My_Variable)(\d+)+/$1.++($_=$2)/eg for @data;
  
  untie @data;
  </code></pre>
  
  <p>Thank you Borodin for getting me started with <code>Tie::File</code>: that definitely helped.</p>
  
  <p>Second solution using while loop</p>
  
  <pre><code>#!perl=C:\IBM\RationalSDLC\ClearCase\bin\perl
  use warnings;
  
  #use strict;
  
  sub inc {
      my ($num) = @_;
      ++$num;
  }
  
  open(FILE, "myfile.txt") || die $!;
  $i = 0;
  while (&lt;FILE&gt;) {
      $string = $_;
      if (/This_Is_My_Variable../) {
          $string =~ s/(This_Is_My_Variable)(\d+)+/$1.++($_=$2)/eg;
          print "$string \n";
          $i++;
      }
      else {
          print "$string \n";
      }
  }
  
  close FILE;
  </code></pre>