Informative post for the archives.
When you are trying to match paths using Regex, it is tempting to use .*? to match a single directory, and while this works in most cases, in certain circumstances it will match multiple directories. It is better to use the match [^/]* as it will match ONLY a single directory.
If I am trying to match the category and type directories under templatedata and I have created an archive directory with a data directory underneath it, the following code and results illustrate the incorrect match.
$path = "/templatedata/cat/type/Archive/data/done.dcr";
$path = ~ m|/templatedata/(.*?)/(.*?)/data/|;
print "match: $1 | $2\n";
---------- Captured Output ----------match: cat | type/Archive
If instead you use the [^/]* pattern you get the following.
$path = "/templatedata/cat/type/Archive/data/done.dcr";
$path =~ m|/templatedata/([^/]*)/([^/]*)/data/|;
print "match: $1 | $2\n";
---------- Captured Output ----------match: |
while this does not match anything, it is correct as it should not match.
-------------------------------
E-Mail :
farnsaw@stonedoor.com