in reply to Regex Substring SORT Conundrum

Creating the hash with "weights" for chapters is definitely a good idea. Now, you just have to parse each citation:
#! /usr/bin/perl use warnings; use strict; use feature qw{ say }; my %order = ( Numbers => 1, Psalm => 2, Matthew => 3, Luke => 4, John => 5, Acts => 6, '2 Corinthians' => 7, Ephesians => 8, Philippians => 9, Colossians => 10, Hebrews => 11, '1 Peter' => 12, ); sub biblically { my @info = map [/(.*?) ([0-9]+):([0-9]+)/], $a, $b; $order{$info[0][0]} <=> $order{$info[1][0]} || $info[0][1] <=> $info[1][1] || $info[0][2] <=> $info[1][2] } my @unsorted = split /\n/, << '__LIST__'; 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 __LIST__ my @sorted = sort biblically @unsorted; say for @sorted;

If the lists are very long, you might preprocess the input by so called Schwartzian transform:

sub biblically { $order{$a->[0]} <=> $order{$b->[0]} || $a->[1] <=> $b->[1] || $a->[2] <=> $b->[2] } my @sorted = map $_->[-1], sort biblically map [/(.*?) ([0-9]+):([0-9]+)/, $_], @unsorted;

You didn't specify how to sort citations like

Ephesians 3:18, 19 Ephesians 3:18-21

To handle all such cases, the biblically subroutine might get even more complicated.

لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

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

    Thank you so much for your prompt and complete reply, with a working example included. I much appreciate it. I tested your example, and it worked fine. However, when I tried to adapt my code to follow your solution, I was still not seeing the results I had hoped (just couldn't seem to get it to work). I don't understand "map" very well at all, and that may be part of my weakness. Yours seemed like a good solution, and perhaps more proper, but I'll be happy with anything that works. In my case, efficiency is not important, as this is not going to run very often, so anything that works, however kludgy it might be, will suit. (Terrible thing to say, I suppose, but sometimes my time is more valuable than the computer's.)

    Blessings,

    ~Polyglot~

      Some of the results that sorted wrongly for you probably had a format different to what you showed here. Can you check that? Also, map is just a for in disguise: in this particular example, it takes the citations, and maps each onto an array reference, containing the book, chapter, verse, and in case of the ST, the citation itself to be retrieved after sorting.
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ