in reply to Re^2: How to have perl check line length
in thread How to have perl check line length

Here's a toy you might find useful:

#!/usr/bin/perl -w use strict; my @TestData = ( 'a', 'NTX', 'NT8', 'NT9', 'NT10', 'NT11', ); { foreach my $inputData (@TestData) { my $outputData = $inputData; while (length($outputData) < 4) { if ($outputData =~ /^(\D*)(\d+)$/) { my $systemType = $1; my $systemNumber = $2; my $totalLength = length($systemType) + length("$syste +mNumber"); while ($totalLength < 4) { $systemNumber = "0$systemNumber"; $totalLength = length($systemType) + length("$syst +emNumber"); } $outputData = "$systemType$systemNumber"; } else { $outputData .= '_'; } } printf "%-4s -> %s\n", $inputData, $outputData; } } exit; __END__

C:\Steve\Dev\PerlMonks\P-2013-09-17@2038-Use-Strict>make4sortable.pl a -> a___ NTX -> NTX_ NT8 -> NT08 NT9 -> NT09 NT10 -> NT10 NT11 -> NT11