in reply to How to match the file and rename the contents in the .config files of directories and subdirectories using perl?

I am not sure what question you are asking?

Your code looks like it should work, but I didn't test it myself. If I were doing this, I would use File::Find to do the recursion instead of implementing it myself. There is also an option of going "bottom up" using finddepth() which could also be considered. This would process all the plain files first (like your .config files) and then process the directory name that those files were in after processing that directories contents.

It appears to me that you have a translation table hash to provide the rules to translate blk3->test and blk1->de_top, etc in the config file (your example of DCMS_DEMO.config). Are you asking how to write that code? This task appears to be straightforward although I would highly recommend making a backup copy of the original config file as a part of the editing process so that you don't loose information in the event of a crash (which might not have anything to do with your program - stuff happens).

It looks to me like you understand the basics. Where are you stuck?

  • Comment on Re: How to match the file and rename the contents in the .config files of directories and subdirectories using perl?

Replies are listed 'Best First'.
Re^2: How to match the file and rename the contents in the .config files of directories and subdirectories using perl?
by finddata (Sexton) on Mar 13, 2017 at 04:05 UTC
    The above code works for matching and renaming the directories.Now i like to do same process for all .config files inside those directories.And another thing it should be done before the last level of the tree(i.e we should omit the file name which ever starts with rev.config from the last level of the directory)
Re^2: How to match the file and rename the contents in the .config files of directories and subdirectories using perl?
by finddata (Sexton) on Mar 13, 2017 at 04:19 UTC
    Things which i really want to deliver you is that as follows:
    1.I have the match file .(from that text file i had matched the word a +nd renamed the names of the directories). 2.After directories matches are done i need to do same process fo all +.config files inside those sub directories and directories. 3.But the point 2 should done without affecting all rev.config files f +rom the same directories and sub directories.
      I see that have have started a number of threads related to this project and that you have written more code since this post.

      I think poj nailed your current problem at Re^5: Unable to rename the contents of the file using perl?. You have to de-reference $string which is a reference a string. In a situation like your code:

      sub write_new_file { my ( $fn, $str ) = @_;
      $fn is a simple string, but $str is actually a reference to a string. I personally would use different variable names to indicate the "type", e.g.
      my ($fn, $str_ref ) = @_; # or $ref_str, $r_str or other possibilities
      This sort of thing can help remind you that to print the contents of $string, you need print $$string instead of just print $string

      If you want process files than end in ".config", but not those like "XXX_rev4.config", a simple way would be to just put

      next if $name =~ /rev\d+\.config$/; if ($name =~ /\.config$/) {blah..blah}