Windows XP escape \D error

G

grocery_stocker

When I run the following...

#!/usr/bin/perl -w

open (PRODUCT,"C:\Documents and Settings\root\Desktop\wd\hp.mhtml") ||
die "Cant open: $!;

I get the following

Unrecognized escape \D passed through at ./parse.pl line 3.
Unrecognized escape \D passed through at ./parse.pl line 3.
Unrecognized escape \w passed through at ./parse.pl line 3.
Unrecognized escape \h passed through at ./parse.pl line 3.
Can't find string terminator '"' anywhere before EOF at ./parse.pl
line 3.

What escape characters is Windows complaining about and how do I fix
them?

Chad
 
J

Jürgen Exner

grocery_stocker said:
When I run the following...

#!/usr/bin/perl -w

open (PRODUCT,"C:\Documents and Settings\root\Desktop\wd\hp.mhtml") ||
die "Cant open: $!;

I get the following

Unrecognized escape \D passed through at ./parse.pl line 3.
Unrecognized escape \D passed through at ./parse.pl line 3.
Unrecognized escape \w passed through at ./parse.pl line 3.
Unrecognized escape \h passed through at ./parse.pl line 3.
Can't find string terminator '"' anywhere before EOF at ./parse.pl
line 3.

What escape characters is Windows complaining about and how do I fix
them?

Why do you think it is Windows that is complaining? It is not.

The first 4 errors are because there is no \D, \w, or \h in Perl. The \r
is ok, because that is the carriage return character <CR>.
See also 'perldoc -q DOS':
Why can't I use "C:\temp\foo" in DOS paths? What doesn't
`C:\temp\foo.exe` work?

The fifth error message doesn't come from Windows, either. You may want
to close the double-quoted string for die().

jue
 
J

Jens Thoms Toerring

grocery_stocker said:
When I run the following...
#!/usr/bin/perl -w
open (PRODUCT,"C:\Documents and Settings\root\Desktop\wd\hp.mhtml") ||
die "Cant open: $!;
I get the following
Unrecognized escape \D passed through at ./parse.pl line 3.
Unrecognized escape \D passed through at ./parse.pl line 3.
Unrecognized escape \w passed through at ./parse.pl line 3.
Unrecognized escape \h passed through at ./parse.pl line 3.
Can't find string terminator '"' anywhere before EOF at ./parse.pl
line 3.

The last one is because you forgot the closing double quote
after "Cant open: $!".
What escape characters is Windows complaining about

It's not Windows complaining but Perl and these are just
warnings. The thing you rather likely don't want isn't
even flagged, see below.
and how do I fix them?

The backslash gives characters a different then their normal
meaning (e.g. \r ist the carriage return character, so you
don't get a complaint about that even though I am sure you
didn't intend to have a carriage return in the file name
before the 'oot';-)

Solutions:

1) Enclose the string with the file name in single instead of
double quotes because in that case the string is taken as
it is and the backlash isn't treated as an escape character.
2) Instead of a single backslash use double backslashes.
3) Use a slash instead of a backslash as the path separator,
it will still result in the correct file being picked (as
it does e.g. for in the "#!/usr/bin/perl" line)

And a few more hints:

instead of '-w' use below the "#!/usr/bin/perl" line

use warnings;

Always also use

use strict;

unless you have a good reason not to.

Use a normal variable for the file handle, e.g.

open my $product, 'filename' or die "Can't open $!";

Regards, Jens
 
J

Jürgen Exner

grocery_stocker said:
When I run the following...
open (PRODUCT,"C:\Documents and Settings\root\Desktop\wd\hp.mhtml") || [...]
I get the following
Unrecognized escape \D passed through at ./parse.pl line 3.
Unrecognized escape \D passed through at ./parse.pl line 3.
Unrecognized escape \w passed through at ./parse.pl line 3.
Unrecognized escape \h passed through at ./parse.pl line 3.
What escape characters is Windows complaining about

It's not Windows complaining but Perl and these are just
warnings.

True, but ignoring those warnings is probably not a good idea. I doubt
the OP has a file named
C:Documents and Settings
ootDesktopwdhp.mhtml

jue
 
J

Jens Thoms Toerring

Jue?rgen Exner said:
grocery_stocker said:
When I run the following...
open (PRODUCT,"C:\Documents and Settings\root\Desktop\wd\hp.mhtml") || [...]
I get the following
Unrecognized escape \D passed through at ./parse.pl line 3.
Unrecognized escape \D passed through at ./parse.pl line 3.
Unrecognized escape \w passed through at ./parse.pl line 3.
Unrecognized escape \h passed through at ./parse.pl line 3.
What escape characters is Windows complaining about

It's not Windows complaining but Perl and these are just
warnings.
True, but ignoring those warnings is probably not a good idea. I doubt
the OP has a file named
C:Documents and Settings
ootDesktopwdhp.mhtml

I didn't realize that

really means that the backslash is simply stripped off... So
things are even worse than I thought;-) Should have been clear
since an escaped character that isn't a character that gets
converted to something else via a backslash translates to the
same character, but the text of the warning got me confused...

Regards, Jens
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,001
Messages
2,570,250
Members
46,848
Latest member
Graciela Mitchell

Latest Threads

Top