by jprzybyl · 10y ago · 0 comments
I honestly don't know. Is the intended purpose of this program to reverse bytes, or reverse characters, or reverse grapheme clusters? Or extended grapheme clusters?
There's no spec - this has never been in POSIX. What is your expected behavior? Is it mine?
For what it's worth, I needed rev recently, but forgot that it existed and did this:
perl -ne 'chomp; print scalar reverse . "\n"'
If I need it to handle UTF-8 in a certain way, I can use pragmas to change it's behavior. (I'm pretty sure that this, as it is, will ignore the surrounding locale.)UTF8 can not be handled in several ways without breaking it, it's a pretty straightforward and strict encoding.
nôn
nôn
Sending that through rev (with a UTF-8 locale), I get n̂on
nôn
By the way, did you know the perl -l flag removes newlines on input and adds them for a print, so your command could just be: perl -lne 'print scalar reverse'
And, for a unicode-aware version: perl -CDS -lne 'print scalar reverse'