Hi, I am seriously stuck with problem and I could use some help. I am having problem writing a script that read a text file which contain a list of files that need to be rename or updated if they contain a certain string such as "d25573786-" to "css12345".
The file I am reading from contain the following : c:\\tmp\\05152003.Log c:\\tmp\\d25573786-.Log c:\\tmp\\drwtsn32.log c:\\tmp\\nbenv10 c:\\tmp\\nbenv11 c:\\tmp\\nbenv12 Here a snippet of my script which I ran in the c:\ drive : use strict; use File::Find; use Sys::Hostname; my $fileupdate; my $old_hostname = "d25573786-"; my ($orig,$concat,$new_hostname,$answer); my @lines = " "; my $new_hostname = ""; ## Create new hostname based on physical address ### $new_hostname = shift; if ($new_hostname eq "" ) { $new_hostname = "css12345"; print "Current host name of machine is :$old_hostname \n"; print "The new host name is going to be: $new_hostname\n"; } if ( $old_hostname ne $new_hostname ) { &personalization; } else { print "System already personlized\n"; } chmod( 0777, $orig ); #--------------------------------------------------------------------- +------------------------ sub personalization { open(FH,"<c:\\person.txt") || die "Can't open arp.txt: $!\n"; while(my $line = <FH>) { if( $line =~ /(.*)$old_hostname(.*)/i ) # any files that cont +ain the substring of the old hostname { print "file that match $line\n"; $orig = $line; $concat = $line; $concat =~ s/(.*)$old_hostname(.*)/$1$new_hostname$2/gi; #CALL UPDATE SUBROUTINE rename($orig, $concat) || print "error can't rename $orig + to $concat: $!"; &modified_file($concat); } else { &modified_file($orig ); } } } #--------------------------------------------------------------------- +------------------------ sub modified_file { $fileupdate = shift; open (IN,"<$fileupdate"); @lines = <IN>; close IN; my $change_count = 0; @lines = map { $change_count++ if s/$old_hostname/$new_hostna +me/sgi; $_ } @lines; next unless $change_count; open (OUT,">$fileupdate") || "can't open $fileupdate for writ +ing :$! "; print OUT @lines; close OUT; }
I keep getting the message can't rename, permission denied. If someone have a better script or know how to fix the problem let me know. --thanks

In reply to Problem with Renaming script by kirk123

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.