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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Regex Substring SORT Conundrum
by Polyglot (Chaplain) on Mar 05, 2015 at 16:41 UTC | |
by BrowserUk (Patriarch) on Mar 05, 2015 at 16:47 UTC | |
by Polyglot (Chaplain) on Mar 05, 2015 at 17:04 UTC |