Avatar of itnifl
itnifl
Flag for Norway asked on

Getting Chinese from my Perl script or browser

My Perl script creates xml and outputs it to the browser. However, the code is not working as it should. The funny part is that I got a bunch of chinese letters as output, or maybe the browser interpreted it that way, I don't know. I am using Chrome. Got to wonder if anything of this makes sense?

Adding the letters as a screenshot, they won't display correctly here on the webpage.

Google translate couldn't make much out of it..
Chinese.png
Web BrowsersPerlWeb Development

Avatar of undefined
Last Comment
itnifl

8/22/2022 - Mon
SOLUTION
Jax Tan

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
Mazdajai

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
itnifl

ASKER
I did it this way:

use XML::Writer;
use CGI;
use CGI::Pretty;
use CGI::Carp qw/fatalsToBrowser warningsToBrowser/;

my $cgi=new CGI;

sub writeXMLToBrowser {
	my $stuff = shift;
	my $output = "";
	$stuff = "Obsolete" if(!defined($stuff));
	my $writer = XML::Writer->new(
		OUTPUT      => \$output,
		DATA_MODE   => 1,
		DATA_INDENT => 1,
		NEWLINES => 0
	);
	$writer->xmlDecl('UTF-8');
	$writer->startTag('info');
		$writer->startTag('stuff');
		$writer->characters($stuff);
		$writer->endTag('stuff')
	$writer->endTag('info');
	$writer->end();
	print $cgi->header('text/xml'), $output;
}

Open in new window


And that works without any Chinese output to my browser. But I still think those characters were weird, and wonder where they came from. Google translate did translate it from Chinese to English, so the characters must have been Chinese, but the translation made no sense.
ASKER CERTIFIED SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
itnifl

ASKER
I understand - the code shown above is the code that now is working. I send text to the sub and it outputs it as xml. The sub shown here is a bit revised, so this one only shows two tags nested. The idea is the same as what I use in my code though.

The code that produced the chinese characters was simply a print statement with an xml header, as shown in the thread here above(e.g.  <?xml version="1.0" encoding="UTF-8"?>) and then another print statement with my xml code in one long string (e.g "<tag1><tag2></tag2></tag1>").

Weird stuff that chrome should pick up Chinese letters as a result of that. Do the Chinese letters have some kind of ascii codes? Is it possible that my previously invalid code could output something that could have been interpreted as ascii codes for Chinese by the browser?
itnifl

ASKER
I guess there is no more a solution to this then displayed here..
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy