Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 07-12-2007, 02:44 PM   #1
LQ Newbie
Registered: May 2007
Posts: 19

Rep: Reputation: 0
perl regular expressions

Hi all,

I'm writing a CGI in which I get some data from a database and then display it using xml. The problem is that let's say the data is "data1" and "data2". I save these two values into an array, but there's an extra character saved with them as well. If I display the array using html, this is the result:


If I just run the perl/cgi script in linux, the output is correct, which is:


If I run the perl/cgi script in linux and save the output to a text file this is what will appear in the file:


I tried using the regex $data1=~s{[\W\_D]}{}g, but it removes all the spaces between the words as well and I don't want that.

Any help is appreciated.
Old 07-12-2007, 05:06 PM   #2
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 30
The ^@ suggests that the offending character is a null character; that is, all bits are off.

But even though NUL characters present a rather unusual case for regular expressions, it's not the case that all bets are off, because you can get rid of null characters in a string thus:

So if my guess is right, that will get rid of the symptom.

You can check whether my guess is right by running this Perl fragment on your string (before removing the NUL character):



  if(($up[$jndex]>=0x20) &&
    printf(sprintf(" %c",$up[$jndex]));

... and you may want to do that, because I'm sure that this code is important enough to you not only to get rid of the symptom, but remove the underlying cause of the problem. Otherwise, that problem may come back to bite you in worse ways than just showing a quirky character on the browser's screen.

Hope this helps.

Last edited by; 07-12-2007 at 05:08 PM.
Old 07-13-2007, 01:50 AM   #3
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,417

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
I'd sanity check the data input code. That looks like a ctrl char eg newline (\n) or something like that.
What do you get if you use interactive SQL to do an SQL like
SELECT concat('X', data-col, 'X')
or equiv; ie try to concatenate an X against each end of the data val?
Old 07-13-2007, 11:56 AM   #4
LQ Newbie
Registered: May 2007
Posts: 19

Original Poster
Rep: Reputation: 0
thanks for your replies. it's working fine now.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Regular Expressions, Perl, everything but a / xemous Programming 6 05-22-2006 11:09 AM
Perl regular expressions CyberJedi Programming 2 10-02-2005 12:17 PM
Perl regular expressions daYz Programming 6 08-11-2005 08:27 AM
Perl and Regular Expressions Fonk Programming 1 06-27-2004 12:32 PM
Perl Regular Expressions true_atlantis Programming 1 11-15-2003 06:16 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:33 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration