title: How to print all filenames in a directory while running line by line on all the files
body: <p>The program I wrote goes through all the files in directory and sub directories line by line and does some commands the include $counter.
  I would like to make a .txt file every line will look like this:</p>
  
  <pre><code>&lt;file name&gt; &lt;$counter in the beginning of the file&gt;
  </code></pre>
  
  <p>For example if I have three file a.txt , b.txt and c.txt in file a the counter counts 10 in file b it counts 20 and in file c it counts 30 the file would look like this:</p>
  
  <pre><code>a.txt 0
  b.txt 10
  c.txt 20
  </code></pre>
  
  <p>My program looks like this:</p>
  
  <pre><code>use strict;
  use warnings;
  use File::Find;
  
  my $dir = "C:/New Folder";   
  open (MYFILE, '&gt;&gt;data.txt');
  
  # fill up our argument list with file names:
  find(sub { if (-f &amp;&amp; /\.[c]$/) { push @ARGV, $File::Find::name } }, $dir);
  $^I = ".bak";   # supply backup string to enable in-place edit  
  
  foreach $argvv(@ARGV)
  {
    while (&lt;&gt;) 
    {
       if ($prev_arg ne $argvv)
       {
         print MYFILE  "$argvv $counter\n";
         $prev_arg = $argvv;
       }   
  
       #some unrelated line by line code here
       close (MYFILE); 
    }
  }
  </code></pre>
  
  <p>What I was trying to do is to make the program print the file name and the counter every time it finishes going through a file and starts another one.</p>
  
  <p>The data.txt file i get is the name of the first file and the counter printed for each line of each file in the directory.
  Needless to say that I'm a total noob in Perl so I would really appreciate some help.</p>
  
  <p>Thanks :)</p>