Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: rename issues

by ikegami (Patriarch)
on Nov 29, 2004 at 17:36 UTC ( [id://410976]=note: print w/replies, xml ) Need Help??


in reply to rename issues

Is the problem the EXAMPLE in the new output? You're doing case sensitive substitutions, and you never look for EXAMPLE in uppercase.

Replies are listed 'Best First'.
Re^2: rename issues
by sunadmn (Curate) on Nov 29, 2004 at 17:39 UTC
    yeah I fixed that forgot the i switch to my switch, but the issue I have now is still that I want to do the work in the new file not the old file and it's not working I know I am missing something stupid just not sure what I am missing.
    SUNADMN
    USE PERL

      Your variable names are very confusing. You're looking for $old_name in file $new?? In fact, I think you confused yourself. Use consistent, meaningful names.

      Is this what you want?

      sub fc { # Pass by reference for efficiency. local $_; *_ = \$_[1]; return uc(substr($_, 0, 1)) . lc(substr($_, 1)); } sub match_case { # Very simplistic. # Pass by reference for efficiency. our $template; *template = \$_[0]; our $s; *s = \$_[1]; return uc($s) if (uc($template) eq $template); my $first_char = substr($template, 0, 1); return fc($s) if (uc($first_char) eq $first_char); return lc($s); } sub wanted { if ((-f $File::Find::name) && ($File::Find::name !~ m/\.bak/)) { my $old_file_name = $File::Find::name; (my $new_file_name = $old_file_name) =~ s/$old_name/$mname/; # # Make backup # rename($new_file_name, $new_file_name.'.bak'); local *IN; open(IN, '<' . $old_file_name) or die("Unable to open old file: $!$/"); local *OUT; open(OUT, '>' . $new_file_name) or die("Unable to create new file: $!$/"); while (<IN>) { s/($old_name)/match_case($1, $mname)/eig; print OUT $_; } close(OUT); close(IN); unlink($old_file_name); } }

      Update: Added match_case.

      Update: Added unlink as per later discussions.

        Ok so the only thing I am missing here is that I do no want to make a backup of the old file all I want to do is rename the old to the new then open the new for writing and make the switches in the new file.
        SUNADMN
        USE PERL
        Yes this is exactly correct thank you much for fixing my problem.
        SUNADMN
        USE PERL

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://410976]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-25 15:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found