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:
$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.sub write_new_file { my ( $fn, $str ) = @_;
This sort of thing can help remind you that to print the contents of $string, you need print $$string instead of just print $stringmy ($fn, $str_ref ) = @_; # or $ref_str, $r_str or other possibilities
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}
In reply to Re^3: How to match the file and rename the contents in the .config files of directories and subdirectories using perl?
by Marshall
in thread How to match the file and rename the contents in the .config files of directories and subdirectories using perl?
by finddata
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |