Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
So a standard reverse sort expression serves in all cases.

As I /msg'ed you at the time you posted this, I had a doubt about this - and now I've finally found the time to confirm that I wasn't being entirely paranoid ;-) Under locale, it's possible for longer strings to be sorted before shorter ones. Here are the instructions to reproduce (on a Debian-based system):

$ mkdir -v /tmp/localetest; cd /tmp/localetest # copy "en_US" and the files it refers to via its "copy" statements $ cp -v /usr/share/i18n/locales/{en_US,en_GB,i18n,iso14651_t1,iso14651 +_t1_common} . $ mv -v en_US en_TESTING

Now edit the file en_TESTING and insert the following into the LC_COLLATE section after the copy "iso14651_t1" statement:

collating-element <bc> from "<U0062><U0063>" script <TESTING> order_start <TESTING>;forward;forward;forward;forward,position <bc> "<a><c>";"<BAS><BAS>";"<MIN><MIN>";IGNORE order_end

Now compile and test the locale:

$ localedef -i en_TESTING -f UTF-8 -c ./en_TESTING.UTF-8 $ LOCPATH=/tmp/localetest LC_ALL=en_TESTING.UTF-8 perl -Mlocale -le 'p +rint for sort qw/ab a b bc/' a ab bc b $ LOCPATH=/tmp/localetest LC_ALL=en_TESTING.UTF-8 perl -wMstrict -lMlo +cale print "1 $_" for "abcabbc"=~/${\join "|", reverse sort qw(b bc) }/g; print "2 $_" for "abcabbc"=~/${\join "|", sort {length$b<=>length$a} q +w(b bc) }/g; __END__ 1 b 1 b 1 b 2 bc 2 b 2 bc

Now of course the real locale definitions are long and I don't plan on reading all of them, and so it's entirely possible that currently no locales exist that define this kind of sorting order. But I'll just be a bit paranoid and stick with sorting by length explicitly :-)

Update: I did incorporate your suggestion about highlighting the fact that strings are matched literally, thank you!


In reply to Re^2: [RFC] Building Regex Alternations Dynamically by haukex
in thread Building Regex Alternations Dynamically by haukex

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 romping around the Monastery: (2)
As of 2024-04-20 03:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found