Solved

PERL: The Escape Character

Posted on 2004-04-27
8
1,371 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
 

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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

706 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now