Hello,

>Hi,
>I'm having a problem where somehow a regexp does not work and the program
results in an error >when the regexp is called using a variable.

>Here is my code.

>1 $filename = 'This is a directory\file\sub.txt';
>2 $regex = '\\(\w+\.\w+)$';
>3 if ($filename =~ /$regex/)
>4 {print $1;} else
>5 {print "nothing\n";}

Use the operator qr{string} instead of single quotes.
The perlop man page explains the cause for this using q{string} or 'string'.

>The following error appears when I run the above.
>"Unmatched ) before HERE mark in regex m/\(\w+\.\w+) << HERE $/ at
regexp.pl line 3."

Check your response you are losing a backslash. 

Chris

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to