Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^8: Getting mad with CGI::Application and utf8

by Juerd (Abbot)
on Feb 27, 2008 at 11:09 UTC ( #670590=note: print w/ replies, xml ) Need Help??


in reply to Re^7: Getting mad with CGI::Application and utf8
in thread Getting mad with CGI::Application and utf8

Let me repeat the question

Do you expect me to repeat the answer too? :)

If your subroutine or module specifically only handles binary strings, I'd recommend documenting it as such, and downgrading the string that you receive:

my $copy = $foo; utf8::downgrade($copy) or utf8::encode($copy) && carp "Wide character +in operation";
That's more or less what Perl does in its binary operators, like print.

Whatever you do, though, never assume that the absence of the flag means it's not a text string!

Juerd # { site => 'juerd.nl', do_not_use => 'spamtrap', perl6_server => 'feather' }


Comment on Re^8: Getting mad with CGI::Application and utf8
Download Code
Re^9: Getting mad with CGI::Application and utf8
by moritz (Cardinal) on Feb 27, 2008 at 11:19 UTC
    Do you expect me to repeat the answer too?

    No. Your anser ("you can't") is probably right, but not very helpful for the situation I described. When I need to solve a problem, and I can't get the 100% complete solution, I try to approximate.

    So I suggested an approximation, and asked if there's a better way. So, is there one? Or is it already as close as I can get, without having to read a foreign module, possibly tracing strings manually through thousands of lines of code?

      Approximations, also known as heuristics, are bound to go wrong at some point. Making decisions (other than downgrading) based on the utf8 flag is bad, and there is no "better" way to do the impossible.

      In any case, document the problem. If at all possible, try to get the data source and/or its documentation to communicate the type to you.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://670590]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2014-12-26 22:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls