CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



strathglass
New User

Jul 15, 2009, 6:46 AM

Post #1 of 3 (2478 views)
Problem matching to pattern with variable Can't Post

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

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

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

Here is my test:

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

where $dxlSourcePath is set to:
"//Server//path//VYE//users.SYS"

It is not working.

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

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

The output from above is:

Code
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.


KevinR
Veteran


Jul 15, 2009, 10:30 AM

Post #2 of 3 (2476 views)
Re: [strathglass] Problem matching to pattern with variable [In reply to] Can't Post

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


Code
$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
-------------------------------------------------


strathglass
New User

Jul 15, 2009, 12:23 PM

Post #3 of 3 (2473 views)
Re: [KevinR] Problem matching to pattern with variable [In reply to] Can't Post

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).

-strathglass

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives