0

For following strings with quotemeta enabled, the if statements are not able to match .cpp and .o file names. Am I doing anything wrong here.

E\:\\P4\\NTG5\\PATHOLOGY_products\\arm\-qnx\-m650\-4\.4\.2\-osz\-trc\-dbg\\gen\\deliveries\\ntg5\\arm\\api\\sys\\most\\pf\\mss\\src\\private\\DSIDSYSMOSTServerMoCCAStream\.cpp\

`E\:\\P4\\NTG5\\PATHOLOGY_products\\arm\-qnx\-m650\-4\.4\.2\-osz\-trc\-dbg\\bin\\deliveries\\ntg5\\arm\\api\\sys\\most\\pf\\mss\\src\\DSIDSYSMOSTServerMoCCAStream\.o\`

        if ($a_path =~ m/[\\>](\w+\.(?:cpp|c))/) {
            $compile_line_array->source_filename($a_path);
            $compile_line_array->include_list_index($include_path_cnt);
            $j=0;
            last;
        } 

        if($a_path =~ m/[\\>](\w+\.(?:o))/) {
            $compile_line_array->object_file($a_path);
        }
aelor
  • 10,892
  • 3
  • 32
  • 48

2 Answers2

2

The regexes match a word character followed by a .; if your strings have a backslash before every ., they will not match.

Somehow, you are not thinking about this correctly: "quotemeta" isn't something that is enabled or disabled, it is an operator that sticks backslashes before some characters in your string. Why are you using it in the first place?

ysth
  • 96,171
  • 6
  • 121
  • 214
  • Looks like the OP is assuming `quotemeta` should be applied on the string instead of the regex – Zaid Mar 13 '14 at 11:15
0

Why do you have your filenames run through quotemeta? As you've demonstrated, that's going to backslash escape all your .'s. Therefore if that's what you want to match against, you'll have to add some backslashes to your regex.

if ($a_path =~ m/[\\>](\w+\\\.(?:cpp|c))/) {

or

if($a_path =~ m/[\\>](\\\w+\.(?:o))/) {
Miller
  • 34,962
  • 4
  • 39
  • 60
  • I need to match windows based path with backslash, with out quotemeta, I was getting following error -- Can't find unicode character property definition via main-e or e.pl at unicode/Is/e.pl line 0 --, hence I used quotemeta. – user3392184 Mar 13 '14 at 06:17
  • I am going to use $a_path =~ s!\\!/!g; to remove all confusion. – user3392184 Mar 13 '14 at 06:20
  • 1
    What following error were you getting? So you used quotemeta since you were trying to avoid some other flaw in your program? I think we're facing an [`XY Problem`](http://www.perlmonks.org/?node_id=542341) here. Why not explain exactly what you're wanting to do before you started getting fancy and what problem you're running into. You can edit your original problem thread. – Miller Mar 13 '14 at 06:21
  • Original problem was I got error: Can't find unicode character property definition via main-e or e.pl at unicode/Is/e.pl line 0 -- because I used split($a_line, /\s+/); which is wrong way of calling since $a_line contain windows path and file name. I changed to split(/\s+\,$a_line), then things are working with out quotemeta. – user3392184 Mar 13 '14 at 06:41