I am new Perl and programming and saw a snippet on here I thought I would try to fix to work for me, but its not working. What am I doing wrong? Any help would be greatly appreciated. For testing I wanted to change all files named "append" to "aPPend"
die("Cannot open /cdw/home_dir/s006258/MarketingDB/.")
unless(opendir(DIR, "/cdw/home_dir/s006258/MarketingDB/"));
#Print to new file
die("Cannot open Log file to read from.")
unless(open(FILES, ">List_of_files_changed.txt"));
print "Reading from file\n";
#reading from file
for my $file (readdir(DIR)) {
if($file =~ /^append/) {
print "$file\n";
$old=$_;
s/^append/aPPend/;
die "$_ already exists" if (-e $_);
print "$old is old and $_ is new\n";
rename($old, $_) or die "Failed to rename\n";
}
}
The output for the last print statemen gives me " is old and new is new" and says "Failed to rename". Thanks again...
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.