"be consistent" | |
PerlMonks |
Re: replace part of directoryby Util (Priest) |
on Aug 22, 2009 at 20:12 UTC ( [id://790607]=note: print w/replies, xml ) | Need Help?? |
When you put a variable in the first section of a s/// substitution, the variable's contents are used as a pattern, not as a simple string. So, c:\top is understood as 5 characters, with the middle character being a TAB ("\t"). You can fix this by using quotemeta. I would also add a start-of-string anchor to be safer. You may need something like make_path from File::Path instead of mkdir when creating multiple levels of directory all at once. Working, tested exmaple code: Output: By the way, you will save yourself some future headaches if you just standardize on POSIX paths (forward slashes instead of backslashes), which *do* work fine in Perl on Win32. I use $path =~ tr{\\}{/} to fix up user input.
In Section
Seekers of Perl Wisdom
|
|