I'm having trouble with the following code:
This simple demo works fine; $destdir gets set to "/some/other/dir/with/more/sub/dirs". I then read files from $srcdir and write them to $destdir, thus replicating the src directory structure.$srcroot = "/some/dir"; $destroot = "/some/other/dir"; $srcdir = "/some/dir/with/more/sub/dirs"; ($extra_path = $srcdir) =~ s/^$srcroot//; $destdir = $destroot . $extra_path; print "extra_path: $extra_path\n"; print "destdir: $destdir\n";
However, in my real code, srcdir is read from the filesystem by recursively scanning from the srcroot provided by the user. I've found that the above code breaks if srcdir contains round brackets (and probably other "special" chars too).
For example:
This prints:$srcroot = "/some/(dir)"; $destroot = "/some/other/dir"; $srcdir = "/some/(dir)/with/more/sub/dirs"; ($extra_path = $srcdir) =~ s/^$srcroot//; $destdir = $destroot . $extra_path; print "extra_path: $extra_path\n"; print "destdir: $destdir\n";
Can anyone suggest a fix for this or an alternative means to achieve what I'm trying to do?extra_path: /some/(dir)/with/more/sub/dirs destdir: /some/other/dir/some/(dir)/with/more/sub/dirs
Thanks,
R.
--
Robin Bowes | http://robinbowes.com
In reply to regex matches with () in strings by robinbowes
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |