Solved

PERL: The Escape Character

Posted on 2004-04-27
8
1,416 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

729 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