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:
Unrecognized escape \M passed through in regex

 



dareno
New User

Jul 28, 2009, 3:35 AM

Post #1 of 4 (3095 views)
Unrecognized escape \M passed through in regex Can't Post

I'm new to Perl, I'm using ActivePerl v5.10.0 and Komodo Edit, running on windows.
My code is:

Code
#!/usr/bin/perl -w 
#use strict;

my $filename = "C:\\Documents and Settings\\pie\\Moje dokumenty\\perl\\dictionary.txt";
my $word = "fiche";

open $filehandle, $filename or die "I couldn't get file: $!";

while ($line = <$filehandle>) {
if ($line =~ /$filename/) {
print $line;
last;
}
}


And the error is: Unrecognized escape \M passed through in regex; marked by <-- HERE in m/C:\Documents and Settings\pie\M <-- HERE oje dokumenty\perl\dictionary.txt/ at C:\Documents and Settings\pie\Moje dokumenty\perl\dict.pl line 10, <$filehandle> line 1.
Could you help?


FishMonger
Veteran / Moderator

Jul 28, 2009, 4:18 AM

Post #2 of 4 (3093 views)
Re: [dareno] Unrecognized escape \M passed through in regex [In reply to] Can't Post

Use forward slashes instead of backslashes.

Code
my $filename = 'C:/Documents and Settings/pie/Moje dokumenty/perl/dictionary.txt';



dareno
New User

Jul 28, 2009, 5:01 AM

Post #3 of 4 (3091 views)
Re: [FishMonger] Unrecognized escape \M passed through in regex [In reply to] Can't Post

Thanks. it works.


shawnhcorey
Enthusiast


Jul 28, 2009, 5:33 AM

Post #4 of 4 (3088 views)
Re: [dareno] Unrecognized escape \M passed through in regex [In reply to] Can't Post


In Reply To

Code
if ($line =~ /$filename/) {


And the error is: Unrecognized escape \M passed through in regex; marked by <-- HERE in m/C:\Documents and Settings\pie\M <-- HERE oje dokumenty\perl\dictionary.txt/ at C:\Documents and Settings\pie\Moje dokumenty\perl\dict.pl line 10, <$filehandle> line 1.
Could you help?


You need to disable the meta-characters in $filename when you do the match.

Code
if ($line =~ /\Q$filename\E/) {


See `perldoc perlre` and search for /\\Q/

Also see `perldoc perlretut`

__END__

I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".

 
 


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

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