Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
*****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); } }
SUNADMN
USE PERL

In reply to rename issues by sunadmn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (6)
As of 2024-03-28 21:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found