robinbowes has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: regex matches with () in strings
by Tanktalus (Canon) on Feb 17, 2005 at 00:26 UTC | |
|
Re: regex matches with () in strings
by sh1tn (Priest) on Feb 17, 2005 at 02:09 UTC | |
by robinbowes (Beadle) on Feb 17, 2005 at 02:25 UTC | |
|
Re: regex matches with () in strings
by gopalr (Priest) on Feb 18, 2005 at 05:01 UTC | |
|
Re: regex matches with () in strings
by tirwhan (Abbot) on Feb 17, 2005 at 10:41 UTC |