I have a script that is trying to re-create a directory structure in a new place. I have a sub that gets passed 3 things (1) the old directory root (2) the new directory root and (3) the particular directory in question. For some reason, I cannot seem to match the old root, to replace it with the new one and create the directory.
Here is the code:
sub newDir {
my $dir = shift;
my $oldroot = shift;
my $newroot = shift;
my $newdir = $dir;
# replace old root dir with new one and create new dir
$newdir = $dir;
$newdir =~ s/$oldroot/$newroot/;
mkdir $newdir;
}
What I am trying to do is to start with:
dir = c:\top\dir\file
oldroot = c:\top
newroot = c:\newtop
and create the directory
newdir = c:\newtop\dir\file
Am I missing something with the substitution? I have tried a number of opstions for s///, but cannot seem to get a match on $oldroot?????
Thanks, Mike
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.