473,503 Members | 11,508 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

trying out escape characters

i'm using ActivePerl, version 5.6.1

My question is:

How come

print "\ "

prints a backslash followed by a space

but

print "\z"

prints the z without a backslash ?

As neither \z nor \+space are Perl escape sequences as far as I know,
i would expect them both to be processed identically ?

Thanks,

Griff
Jul 19 '05 #1
6 14153
gr*****@aol.com (Griff) wrote in message news:<d6**************************@posting.google. com>...
How come

print "\ "

prints a backslash followed by a space
It does not. It prints a space.
print "\z"

prints the z without a backslash ?
Yeah, but it emits a warning.
As neither \z nor \+space are Perl escape sequences as far as I know,
i would expect them both to be processed identically ?


If you have warnings switched off then they appear to be processed
identically.

However, you should not have warnings switched off.

Any non-letter preceded by a backslash represents that literal
character, always.

Any letter preceded by a backslash is potentially a Perl escape
sequence. There may be no \z yet but there may be one in future.
Hense you get a warning. Until and unless \z is defined it is
interpreted as a literal z. If this offends you then you can always
promote the warning to an error.

This newsgroup does not exist (see FAQ). Please do not start threads
here.
Jul 19 '05 #2
(1) apologies for starting a thread in non-existent NG, I will use
comp.lang.perl.misc in future.

(2) i think I know where my confusion arose...

print "\Qz\E";
print "\n";
print "\Q \E";
print "\n";

produces three lines of output,
line 1 : z
line 2 : \
line 3 : (newline)

Why does output line 2 contain a backslash when output line 1 doesn't
?

thanks - Griff
Jul 19 '05 #3
Griff wrote:
(1) apologies for starting a thread in non-existent NG, I will use
comp.lang.perl.misc in future.

(2) i think I know where my confusion arose...

print "\Qz\E";
print "\n";
print "\Q \E";
print "\n";

produces three lines of output,
line 1 : z
line 2 : \
line 3 : (newline)

Why does output line 2 contain a backslash when output line 1 doesn't
?

thanks - Griff


Actually line 2 has a has a backslash followed by a space. The \Q..\E
construct all non word characters with a backslash. A space is not a
word character, hence it returns "\ ". To illustrate, try somthing like:

print "\Qab_cd1:2'3/4? 5\E";
This group is defunct. Please use comp.lang.perl.misc in future.
Jul 19 '05 #4
Griff wrote:
(1) apologies for starting a thread in non-existent NG, I will use
comp.lang.perl.misc in future.

(2) i think I know where my confusion arose...

print "\Qz\E";
print "\n";
print "\Q \E";
print "\n";

produces three lines of output,
line 1 : z
line 2 : \
line 3 : (newline)

Why does output line 2 contain a backslash when output line 1 doesn't
?

thanks - Griff


Actually line 2 has a has a backslash followed by a space. The \Q..\E
construct prepends a backslash to all non word characters. A space is
not a word character, hence it returns "\ ". To illustrate, try somthing
like:

print "\Qab_cd 1:2'3/4?5\E";
This group is defunct. Please use comp.lang.perl.misc in future.
Jul 19 '05 #5
Griff wrote:
(2) i think I know where my confusion arose...

print "\Qz\E";


That's not their purpose. \Q and \E should only be used
a) in the match operator (m//).
b) in the lefthand part of the substitue operator (s///).
c) in creating regular expressions via qr//, to be
used in one of the two above cases.

-Joe
Jul 19 '05 #6
Joe Smith <Jo*******@inwap.com> wrote in message news:<O%DUc.7190$Fg5.7106@attbi_s53>...
Griff wrote:
(2) i think I know where my confusion arose...

print "\Qz\E";


That's not their purpose. \Q and \E should only be used
a) in the match operator (m//).
b) in the lefthand part of the substitue operator (s///).
c) in creating regular expressions via qr//, to be
used in one of the two above cases.


That's not enirely true. quotemeta() (aka \Q...\E) can also be useful
in constructing strings that are to passed to eval() or system().
Jul 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
8512
by: BTnews | last post by:
Hi, Can anyone here point me at a definitive guide or tutorial about using escape characters when building SQL queries from user entered data? I'm especially interested in info on this in regard...
2
43776
by: Matthew Wieder | last post by:
In my previous post, I asked about a routine which prepares a string for an XPath query by taking care of escape characters. Unable to find a list, I'm now wondering assumign I enclose the...
7
96256
by: teachtiro | last post by:
Hi, 'C' says \ is the escape character to be used when characters are to be interpreted in an uncommon sense, e.g. \t usage in printf(), but for printing % through printf(), i have read that %%...
18
7149
by: Steve Litvack | last post by:
Hello, I have built an XMLDocument object instance and I get the following string when I examine the InnerXml property: <?xml version=\"1.0\"?><ROOT><UserData UserID=\"2282\"><Tag1...
16
2129
by: Andrew Baker | last post by:
I am trying to write a function which provides my users with a file filter. The filter used to work just using the VB "Like" comparision, but I can't find the equivilant in C#. I looked at...
4
7458
by: Guadala Harry | last post by:
I need to place the following into a string... How can I properly escape the % " / < and > characters? <table width="100%" border="0" cellspacing="0" cellpadding="4px" class="hfAll"></Table> ...
12
9616
by: Jeff S | last post by:
In a VB.NET code behind module, I build a string for a link that points to a JavaScript function. The two lines of code below show what is relevant. PopupLink = "javascript:PopUpWindow(" &...
0
1456
by: Mike Cooper | last post by:
Hi everyone, I am accessing several binary (PCL) files sequentially using a for loop. For each file I am using the fileget() command to populate the contents of the file into a string. I use...
15
18279
by: pkaeowic | last post by:
I am having a problem with the "escape" character \e. This code is in my Windows form KeyPress event. The compiler gives me "unrecognized escape sequence" even though this is documented in MSDN....
131
9148
by: Lawrence D'Oliveiro | last post by:
The "escape" function in the "cgi" module escapes characters with special meanings in HTML. The ones that need escaping are '<', '&' and '"'. However, cgi.escape only escapes the quote character if...
0
7212
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7364
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5604
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5026
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4696
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
751
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.