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.

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

In reply to Re: Regex Substring SORT Conundrum by choroba
in thread Regex Substring SORT Conundrum by Polyglot

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.