in reply to Regex Substring SORT Conundrum
You can extract the book name by itself with a regex, and compare using the regexes as keys for the hash:
$a=~/^((\d+ )?\w+)/ $abook=$1; $b=~/^((\d+ )?\w+)/; $bbook=$1; if ($sortdata{$abook} > $sortdata{$bbook}) { return 1 } elsif ($sortdata{$bbook} > $sortdata{$abook}) { return -1 } else { return 0 } } # END SUB byBiblicalBookOrder
This doesn't affect the contents of $a or $b themselves, so you can then do the additional sorting based on regexes that pull out the trailing sets of numbers.
edit: if you just want the book names and not the numbers, the regex would be something like /^((\d+ )?(\w+))/ and you'd take the value of $3 to get the book name without the leading number.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex Substring SORT Conundrum
by Polyglot (Chaplain) on Mar 05, 2015 at 16:35 UTC |