Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Greeting perl monks,

Given an array of full file paths (using File::Util), I strip off the root directory using a regex and peform other processing

The regex works fine with perl 5.10.0 on Linux but when I run it with perl 5.10.0 on Windows XP it gives me the following error.

Can't find Unicode property definition "A"

----- code snippet ----- my $fu = File::Util->new(max_dives => 2000); @results = $fu->list_dir($root_dir, qw/ --files-only --recurse /); foreach (@results) { # strip off the $root_dir $_ =~ s!($root_dir\\)|($root_dir/)!!g; } ----- code snippet -----

I looked around and wasn't able to find anything that helped. Thanks in advance for any insight.

Replies are listed 'Best First'.
Re: Can't find Unicode property definition "A"
by Corion (Patriarch) on Sep 30, 2009 at 17:48 UTC

    You haven't shown us the contents of $root_dir, but my guess is that it contains regex metacharacters, like \ or *. You want to either change $root_dir in such a way that it contains forward slashes (/) in stead of backslashes, or you want to use \Q...\E (or quotemeta) when interpolating $root_dir, so that all regex metacharacters loose their meta-ness:

    $_ =~ s!(\Q$root_dir\E\\)|(\Q$root_dir\E/)!!g;

    Also, consider using File::Spec for your filename manipulation, and also consider anchoring your match, so that a relative path won't be stripped out of the middle of the actual directory.

Re: Can't find Unicode property definition "A"
by ikegami (Patriarch) on Sep 30, 2009 at 17:49 UTC
    You're treating $root_dir as a regex pattern, but I doubt that's what it contains. Use quotemeta (directly or via \Q\E) to convert arbitrary text into a pattern that matches the text.
    s!^\Q$root_dir\E[\\/])!! for @results;

    (Simplified and sped up the pattern by removing needless captures and factoring the common prefix out of the alternation.)

      Thank you for the quick replies. It's working now.