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

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.
  • Comment on Re^2: How to match the file and rename the contents in the .config files of directories and subdirectories using perl?
  • Download Code

Replies are listed 'Best First'.
Re^3: How to match the file and rename the contents in the .config files of directories and subdirectories using perl?
by Marshall (Canon) on Mar 14, 2017 at 22:06 UTC
    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}