XML ( WML in particular)

B

Brian

Hi,

I have a script that generates some WML, and I would like this to be written
to a file using the UTF-8 characterset. Currently it is just written
normally , with the affect that my phone wont recognise it.

How is this done in Perl?

Thanks
 
S

Shambo

Brian said:
Hi,

I have a script that generates some WML, and I would like this to be written
to a file using the UTF-8 characterset. Currently it is just written
normally , with the affect that my phone wont recognise it.

How is this done in Perl?

Thanks

open (FILE, ">:utf8", "/somepath/somefile.wml")

This will write your file as UTF-8, change "somepath" to your target
path and file name.

(Slightly OT to Perl) WML is very unforgiving with its range of
displayable characters. Others here may disagree with this method, but
I've found it to be very helpful.

s/([\x{80}-\x{FFFF}])/'&#' . ord($1) . ';'/gse;

That line will change characters above the first 128 ASCII characters
to their numeric equivalent, which WML should be able to display. I
have not personally encountered very high range characters in my WML,
such as "?" and other ligature type characters, but letters with
accents and umlauts display fine in WML when they are converted to
their numeric equivalent.

Also (off-topic to Perl), make sure you keep your file sizes under
1400 bytes. Older phone browsers don't support larger bytestreams.
 
A

Alan J. Flavell

[administrivia at end]

(Slightly OT to Perl)

but since you insist on raising it, don't be too surprised to get a
response ( - and now both of us should not be too surprised to be told
to get ourselves hence to a more appropriate newsgroup...)
WML is very unforgiving with its range of displayable characters.

Could you be more specific? I didn't have time to read the license
terms and consult with my employer and their lawyers whether I was OK
to accept them, so I wasn't able to get to the actual WML
specification at wapforum, but I gathered from what was written here
that utf-8 was wanted, and I answered on that basis.
Others here may disagree with this method, but
I've found it to be very helpful.

s/([\x{80}-\x{FFFF}])/'&#' . ord($1) . ';'/gse;

But what benefit does this bring relative to utf-8 coding, if utf-8
coding is part of the specification?

By the way, where does your data come from, what encoding was it in,
did you remember (obPerl) to tell perl what encoding it was in when
you read or otherwise retrieved it?

I see two things wrong already. The Unicode characters from x80 to
x9f are obscure control characters, not displayable glyphs; if you get
any of those as display characters then something is wrong (probably
Bill Gates got a bit too close to your WML) and presumably you should
reject them, if WML is meant to be as unforgiving as you say.

And then Unicode no longer stops at xffff, there are characters beyond
there. I don't know WML well enough, as you can see, but if it allows
them then why wouldn't you support them; but if they aren't, then why
wouldn't you want to report them as an error?
That line will change characters above the first 128 ASCII characters

Ahem, *bogosity alert*. ASCII is a 7-bit code, the "first 128 ASCII
characters" is all that there are.
to their numeric equivalent, which WML should be able to display.

So it should, but if utf-8 encoding is expected, why not use it? It's
not as if the max document size is generous, so I'd say use the most
compact representation that you are able to. What am I missing?
have not personally encountered very high range characters in my WML,
such as "?" and other ligature type characters,
^^^

eh?? Quick check of your headers shows

| Content-Type: text/plain; charset=ISO-8859-1

Whatever it was that you were trying to type, it seems iso-8859-1
doesn't have it on offer.
Also (off-topic to Perl), make sure you keep your file sizes under
1400 bytes.

Yup, that was my point above.

cheers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,118
Latest member
LatishaWhy
Top