in reply to Regex Substring SORT Conundrum

You didn't post a complete name/number mapping, so you'd need to do that yourself. Switching this line:

$a[ 0 ] cmp $b[ 0 ]

To something like:

nameToNumber{ $a[ 0 ] } <=> nameToNumber{ $b[ 0 ] }

should do it, but this might get you started:

#! perl -sw use strict; print for sort { my @a = $a =~ m[(\w+)\s+(\d+)(?::(\d+))?]; my @b = $b =~ m[(\w+)\s+(\d+)(?::(\d+))?]; $a[ 0 ] cmp $b[ 0 ] or $a[ 1 ] <=> $b[ 1 ] or $2 and $a[ 2 ] <=> $b[ 2 ] or 0; } <DATA>; __DATA__ Acts 4:29-31 Numbers 14:10 Luke 1:20 John 16:15 Acts 2:4 1 Peter 1:22 Psalm 56:3 2 Corinthians 12:2, 4, 1, 11 Ephesians 3:18, 19 Ephesians 4:14, 13, 17, 18; 5:15, 16 Matthew 24:24 Colossians 2:6-8 Hebrews 10:35-39 Hebrews 4:10-12 Philippians 1:6, 27-29 Matthew 7:6-12, 15 Philippians 2:13-15

Produces:

C:\test>junk66 Acts 2:4 Acts 4:29-31 Colossians 2:6-8 2 Corinthians 12:2, 4, 1, 11 Ephesians 3:18, 19 Ephesians 4:14, 13, 17, 18; 5:15, 16 Hebrews 4:10-12 Hebrews 10:35-39 John 16:15 Luke 1:20 Matthew 7:6-12, 15 Matthew 24:24 Numbers 14:10 1 Peter 1:22 Philippians 1:6, 27-29 Philippians 2:13-15 Psalm 56:3

Of course, then you can save a (tiny) bit of time switching to a ST or GRT; but there aren't enough books in the Book to worry about that.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked

Replies are listed 'Best First'.
Re^2: Regex Substring SORT Conundrum
by Polyglot (Chaplain) on Mar 05, 2015 at 16:41 UTC

    I have the full 90 books (including the Apocryphal ones, just in case they're ever needed) in a hash of well over 1000 lines. I didn't figure anyone would wish to peruse it for their reading pleasure, so I shortened it. However, if anyone else wants it, I suppose I could dump the whole thing to a code box here. I guess I'm not sure what the forum does with way-too-long posts. I don't think I'd want it reaped. :) (And I haven't figured out how to make such nice additions to my home node as some posters here seem to do with extra bits like this.)

    Thank you for your suggestions.

    Blessings,

    ~Polyglot~

      a hash of well over 1000 lines.

      NP. I was just explaining why I hadn't dealt with that bit. So long as you understand where and how to use your hash in my snippet, is all that matters.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
      In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked

        I just found that your solution also seems to work. It also does not sort the numbers, just the books, which left me a little puzzled, because it appeared setup to do both. One anomaly came out in the sort...the book of "Numbers" was thrown into the list in the wrong place! (Perl wouldn't be translating the name to a value, would it?) I double-checked the weighting, and there should have been no issue there. Thank you, again, for your helpfulness.

        Blessings,

        ~Polyglot~