*****UPDATE*****
I found the issue in the rename and fixed it I forgot to change a scalar name please disregard.
*****UPDATE*****
Hello all I have a quick question about some code I wrote to rename files under a given dir and then open the file and replace a scalar with another. I have the files being created with the new name, but I also still have the old copy with the old name there, issue number 1. The other issue I have is that the output in the new file is not what I expected, so if this code is correct it should look for the text "example" and switch it with the scalar $mname globaly in the new file this is not happening in the new file but the old file it is.
Example of the sdiff:
sdiff example_user_menu.htm pnDiagram_user_main.htm
Old file output:
<!--[* $Id: pnDiagram_user_menu.htm,v 1.6 2004/01/06 15:17:20 markwes
+t Exp $ *]-->
<!--[pngetstatusmsg]-->
<br />
<div class="pn-title">
<!--[* To get the results of a function for using in another function
+, you *]-->
<!--[* need to capture its output! AFAIK currently there is no other
+way *]-->
<!--[capture name="heading"]--><!--[pnml name="_EXAMPLE"]--><!--[/capt
+ure]-->
<!--[pnimg src="heading.gif" alt=$smarty.capture.heading]-->
</div>
<div class="pn-menuitem-title">
<a href="<!--[pnmodurl modname="pnDiagram" type="user" func="view"]-
+->"><!--[pnml name="_EXAMPLEVIEW"]--></a>
</div>
<br />
New file output:
<!--[* $Id: example_user_menu.htm,v 1.6 2004/01/06 15:17:20 markwest
+Exp $ *]-->
<!--[pngetstatusmsg]-->
<br />
<div class="pn-title">
<!--[* To get the results of a function for using in another function
+, you *]-->
<!--[* need to capture its output! AFAIK currently there is no other
+way *]-->
<!--[capture name="heading"]--><!--[pnml name="_EXAMPLE"]--><!--[/capt
+ure]-->
<!--[pnimg src="heading.gif" alt=$smarty.capture.heading]-->
</div>
<div class="pn-menuitem-title">
<a href="<!--[pnmodurl modname="Example" type="user" func="view"]-->
+"><!--[pnml name="_EXAMPLEVIEW"]--></a>
</div>
<br />
Here is what I have for code:
#!/usr/bin/perl
use strict;
use warnings;
use File::Find;
# We need to gather some info from the user
# here for module name
print "Please enter your module name\n";
print "This would be the name of the directory of your module\n";
my $mname = <STDIN>;
chomp($mname);
# Now we need to know where to look to make
# the changes to files on the system this
# will be our base directory to search through
print "Please enter your modules base directory\n";
print "Example would be /var/www/postnuke/modules/YOUR_MODULE/\n";
my $base = <STDIN>;
chomp($base);
my $old_name = 'example';
my $old_name2 = 'Example';
find(\&wanted, $base);
sub wanted {
if ((-f $File::Find::name) && ($File::Find::name !~ m/\.bak/)) {
my $file = $File::Find::name;
(my $new = $file) =~ s/$old_name/$mname/;
rename($file, $new);
open(IN, $new) or die($!);
open(OUT, '>' . $file) or die($!);
while (<IN>) {
s/$old_name/$mname/g;
s/$old_name2/$mname/g;
print OUT $_;
}
close(OUT);
close(IN);
}
}