Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

The following code creates the test script and runs it:

I don't like that so I rewrote it

#!/usr/bin/perl -- use strict; use warnings; use Data::Dump; my $utf1 = pack 'H*', join'', qw/61 61 c5 99 0a c4 8d 0a 61 61 c5 99 0 +a/; my $utf2 = pack 'H*', join'', qw/c4 8d 0a 61 61 c5 99 0a c4 8d 0a/; dd $utf1, $utf2; utf8::decode( $utf1 ); utf8::decode( $utf2 ); dd $utf1, $utf2; for my $string ( $utf1, $utf2 ){ my @lines = split /\n/, $string; for my $line ( @lines ){ if( my($word) = $line =~ /^(.+)$/ ){ my $one = substr $1, 0, 1; my $wone = substr $word, 0, 1; dd { word => $word, 1 => $1, one => $one , wone => $wone } +; } } dd \@lines; dd; } __END__ ( "aa\xC5\x99\n\xC4\x8D\naa\xC5\x99\n", "\xC4\x8D\naa\xC5\x99\n\xC4\x8D\n", ) ( "aa\x{159}\n\x{10D}\naa\x{159}\n", "\x{10D}\naa\x{159}\n\x{10D}\n", ) { 1 => "aa\x{159}", one => "a", wone => "a", word => "aa\x{159}" } { 1 => "\x{10D}", one => "Ä", wone => "\x{10D}", word => "\x{10D}" } { 1 => "aa\x{159}", one => "a", wone => "a", word => "aa\x{159}" } ["aa\x{159}", "\x{10D}", "aa\x{159}"] () { 1 => "\x{10D}", one => "Ä", wone => "\x{10D}", word => "\x{10D}" } { 1 => "aa\x{159}", one => "a", wone => "a", word => "aa\x{159}" } { 1 => "\x{10D}", one => "Ä", wone => "\x{10D}", word => "\x{10D}" } ["\x{10D}", "aa\x{159}", "\x{10D}"] ()

I've got perl 5.014001 and I get these from Data::Dump Malformed UTF-8 character (unexpected end of string) and Wide character in print , it appears the utf flag gets turned off when substr-ing on $1 under some cases, and it appears this bug has surfaced before https://rt.perl.org/rt3/Public/Search/Simple.html?q=%241%20utf

But I'm no expert


In reply to Re: Substring giving strange results on $1 with utf8 by Anonymous Monk
in thread Substring giving strange results on $1 with utf8 by choroba

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (6)
As of 2024-04-19 11:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found