Home: Perl Programming Help: Regular Expressions:
Problem matching to pattern with variable

New User

Jul 15, 2009, 6:46 AM

Views: 5810
Problem matching to pattern with variable

Trying to find lines like this in an input file to be processed:

#include <//Server//path//VYE//users.SYS//filename.inc>

(so I can create a new output file with modified path info).

Here is my test:

if ($line =~ m/^(#include[ \t]+<)$dxlSourcePath(.*)/i)

where $dxlSourcePath is set to:

It is not working.

What is confusing is the output from the following debug printout:

printf("NO MATCH to pattern /^(#include[ \\t]+<)$dxlSourcePath(.*)/i for line='$line'\n");

The output from above is:

NO MATCH to pattern /^(#include[ \t]+<)//Server//path//VYE//users.SYS///(.*)/i for line='#include <//Server//path//VYE//users.SYS//utils.inc>^M'

Notice the three trailing slashes at the end of the printed $dxlSourcePath value, before the string '(.*)':
where the heck did they come from??

Any help appreciated.

Regards, Strathglass.


Jul 15, 2009, 10:30 AM

Views: 5808
Re: [strathglass] Problem matching to pattern with variable

Works for me as-is. I suspect your problem is elsewhere but where I have no idea.

$line = '#include <//Server//path//VYE//users.SYS//filename.inc>'; 
$dxlSourcePath = '//Server//path//VYE//users.SYS';
if ($line =~ m/^(#include[ \t]+<)($dxlSourcePath)(.*)/i){
print "It matches: [$1] - [$2] - [$3]\n";
else {
print "It does not match\n";

the [] brackets are there in the printout so you can see what is matching

New User

Jul 15, 2009, 12:23 PM

Views: 5805
Re: [KevinR] Problem matching to pattern with variable

Thanks. Maybe it is something wacky with my SFU package on Windows.
I will try it out on a different platform (my Mac or ActiveState perl on Windows).