Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
The documentation of Perl's reverse function states: "In scalar context, [the reverse function] ... returns a string value with all characters in the opposite order."
No. It doesn't know anything about Unicode and there's no requirement for the string to be Unicode text.

The documentation is quite clear: In scalar context, the reverse function operates on strings. If the string is Unicode, it reverses Unicode code points. If the string is in some single-byte character encoding such as ISO 8859-1 (Latin 1), then it reverses those characters. It's really very straightforward.

You're once again trying to make some esoteric point about the distinction between strings and bytes, and what is Unicode and what is not Unicode. But your peculiar, persistent point isn't relevant here.

Nothing in my post is incorrect or inaccurate, yet the supercilious tone of your response wrongly implies that something is incorrect. The topic of this discussion is Unicode text, so of course I'm talking about Unicode text in it.

In my experience, "character" is the constituent element of a string, and never a grapheme except by happenstance. Let's just say there is no such consensus.

What is a character in a language is well-understood and rarely, if ever, subject to debate. In the case of Unicode, "character" is well-defined, too: It's a "grapheme." It's as simple as that. Read the Unicode Standard.

There are four characters in the word "Caf", not five. When you arrange the four characters in the opposite order, you get "faC". This fact is the very basis of this tutorial and discussion.

No. reverse provides a vital string operation. It should not assume the string is Unicode text.

Your insistence that there's a difference between "string" and "text" may have some strange basis in the arcane details of the internals of Perl, but it has no relevance to this discussion. The whole premise of this discussion is that we're trying to reverse Unicode strings (Unicode text). And the salient point about Perl's reverse function is that it fails to reverse properly an infinite number of possible Unicode strings.

Reversing text is also a useful function, but it is not provided by reverse.

This is a bizarre and incomprehensible statement.

What's the difference between a "string" and "text" to someone writing a Perl program?

Explain why you think this

use utf8;

binmode STDOUT, ':encoding(UTF-8)';

my $Moonshine = "Rươu ê";
my $enihsnooM = reverse $Moonshine;

print "$Moonshine\n";
print "$enihsnooM\n";

should produce different output than this

use utf8;

binmode STDOUT, ':encoding(UTF-8)';

my $Moonshine = "Rươu ê";
my $enihsnooM = join '', reverse $Moonshine =~ m/\X/g;

print "$Moonshine\n";
print "$enihsnooM\n";

In reply to Re^3: How to reverse a (Unicode) string by Jim
in thread How to reverse a (Unicode) string by moritz

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

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    [ambrus]: wait. I understand no wife and children, but how do you not have to pay for a house?
    [hippo]: I had a low-paid job about 20 years ago and seriously considered going down to a 3-day week. Would have worked 60% of the time for about 80% of the cash.
    [Corion]: ambrus: Well, I pay rent, but don't own a house with variable/ unforeseeable costs
    [hippo]: The thesholds/benefits balance at the time was nuts.
    [hippo]: But that doesn't last because, you know ... politicians. :(
    [Corion]: hippo: Yeah, if you still get enough money to get by and don't have expensive hobbies or other fixed costs that can work out well
    [ambrus]: ah good. I pay only rent too. but that still costs significant money.
    [Corion]: ambrus: Yes, but that is already budgeted for

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (8)
    As of 2017-09-21 15:19 GMT
    Find Nodes?
      Voting Booth?
      During the recent solar eclipse, I:

      Results (249 votes). Check out past polls.