Solved

PERL: The Escape Character

Posted on 2004-04-27
8
1,389 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

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…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

803 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