Solved

PERL: The Escape Character

Posted on 2004-04-27
8
1,398 Views
Last Modified: 2008-03-03
Hello,

We have a program written in Perl that uses a database.  For one part of the databse, we want to use Chinese characters for the name.  The unicode for the Chinese characters all begin with:

&#

and then a four digit number and then a semicolon.  So, something like this:

ᄢ

Using these to name the database throws it off.  It cuts everything from the first # symbol.  Is there anyway within Perl that we can set these characters so they can be handeled?  We tried putting them between two backslashes, but that didn't work.  A kind soul over in the Databases section suggested the following.  What is your opinion:

SOUNDS LIKE MIGHT NEED THE ESCAPE CHARACTER BEFORE THE # BUT I DO NOT KNOW WHAT THIS IS FOR PERL.


Many thanks,

Yunkaa
0
Comment
Question by:yunkaa
  • 5
  • 3
8 Comments
 

Author Comment

by:yunkaa
ID: 10930543
peep.... peep...

Perl experts, please help! ... peep...

Yunkaa
0
 
LVL 7

Expert Comment

by:minnirok
ID: 10932712
The escape character for perl is backslash (\) as is common in most mainstream languages.  This isn't the problem, however, since # does not need to be escaped as it is interpreted litterally as # within a string.

If you are attempting to name a database, database table, or database field then your problem is likely arrising from the semicolon (;) within the unicode.  When SQL runs into this semicolon, it will terminate the query and most likely return an error.  You need to enclose these field names within the single tic-mark quotes (`) - the key that shares the tilda key (~) to the left of the 1-key.

you can also use qq() in perl to act as quotes around your query.

$query = qq~ CREATE TABLE `ᓠಬ` ( `field1` INT NOT NULL , PRIMARY KEY( `field1` ) ); ~

qq takes any symbol you specify as it's delimiter for the statement, so you could just as easily use:

$query = qq* CREATE TABLE `ᓠಬ` ( `field1` INT NOT NULL , PRIMARY KEY( `field1` ) ); *

anyway, I'm not sure this completely addresses what you're trying to do.  Good luck.
0
 

Author Comment

by:yunkaa
ID: 10932764
Hello minnirok,

We will test now.  Thank you so much for replying ! :))))))))))))))))))))))))))))))))))))

Yunkaa

0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:yunkaa
ID: 10932861
Hello minnirok,

Thanks again for posting! :) We really appreciate your time and help.  We tried the ` symbol.  It didn't work, BUT we have some additional clues!  Woth your level of insight there may be a clue in them.

This is a sub, sub-section of our database.  It is created in a db file. An example name would be:

中文

When creating this subsection, it <b>accepts</b> the two characters in the db and renders the subsection, with the chinese characters.  But, in the resulting link into the database, the characters come back as

ampersand#20013;ampersand25991;

In the breadcrumb trail are only rendered as

Section Name > Subsection1 > &

where the ampersand is the only thing that represents the subsection we created.

Many thanks x 1,000,000,000,

Yunkaa
0
 
LVL 7

Expert Comment

by:minnirok
ID: 10933277
So, are the characters are being correctly inserted into the database?  The first thing I'd do is check the database to make sure that the characters were input successfully in the first place.

I'm unsure of the specific problem that is occuring here - are you reading from the database and writing out to a webpage using perl?

you could try using the HTML syntax for an ampersand, which is &amp;

for reference, the world wide web consortium has a site dedicated to the issue of internationalization.  so this may be of use to you:

http://www.w3.org/International/
0
 

Author Comment

by:yunkaa
ID: 10933349
Hello minnirok,

Yes, we are reading from the database and writing out to a webpage using perl but characters don't get input correctly.  When we enter:

&#20013;&#25991;

in the db file
it saves them as:

ampersand#20013;ampersand25991;

and the web page output lists the two chracters only as

&

the ampersand symbol.

Many, many, many thanks,

Yunkaa
0
 
LVL 7

Accepted Solution

by:
minnirok earned 500 total points
ID: 10933615
What database are you using?  It sounds like the database does not support the ampersand character, and is converting it to a the literal word "ampersand"...

What may be happening, is that the # character is being interpreted by perl as a comment for that line, so it's cutting everything off after the first ampersand.  Do you have any sample code for what you're doing?  It may be easier to spot what's going wrong....

0
 

Author Comment

by:yunkaa
ID: 10952853
What database are you using?
Not sure.

 Do you have any sample code for what you're doing?
The developer won't let us post sample code... :((

Many thanks,

Yunkaa

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
TripAdvisor Widgets on WordPress Websites 10 189
File names with & character 6 81
Coova-Chilli can't work with URL using HTTPS! 3 272
replace quotes with UTF-8 character 38 104
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question