#!/usr/bin/perl use warnings; use strict; my %tagTypes = ( code => ['code', 'code', ''], bold => ['b', 'Bold', 'F'], teletype => ['tt', 'Teletype text', 'F'], id => ['link id://', 'Node id link', 'L'], readmore => ['readmore', 'Readmore', 'RB'], readmoretitle => ['readmoretitle', 'Readmore Title', 'RTB'], ); my @tagIndexes = ( ['on', 'code', '1.0'], ['off', 'code', '3.6'], ['on', 'id', '3.9'], ['on', 'bold', '3.9'], ['off', 'id', '3.20'], ['off', 'bold', '3.20'], ); print join "\n", map {"$_->[0] $_->[1] $_->[2]"} sort modeOrder @tagIndexes; sub modeOrder { # Sort compare routine to order tags by markup generation order my ($aType, $aItem, $aIndex) = @$a; my ($bType, $bItem, $bIndex) = @$b; return $_ if ($_ = int ($aIndex) <=> int ($bIndex)); $aIndex =~ s/\d*\.//; $bIndex =~ s/\d*\.//; return $_ if $_ = $aIndex <=> $bIndex; return $_ if $_ = $aType cmp $bType; my $aMode = ${$tagTypes{$aItem}}[2]; my $bMode = ${$tagTypes{$bItem}}[2]; return flagValue ($aMode) <=> flagValue ($bMode) if $aType eq 'on'; return flagValue ($bMode) <=> flagValue ($aMode); # off case } sub flagValue { my $flags = shift; return 1 if -1 != index $flags, 'R'; return 2 if -1 != index $flags, 'T'; return 3 if -1 != index $flags, 'B'; return 4 if -1 != index $flags, 'I'; return 5 if -1 != index $flags, 'F'; return 6 if -1 != index $flags, 'L'; return 7; } #### on code 1.0 off code 3.6 on bold 3.9 on id 3.9 off id 3.20 off bold 3.20