in reply to How to have perl check line length

Okay, TMTOWTDI time.

#!/usr/bin/perl -w use strict; my @TestData = ( 'NT8', 'NT9', 'NT10', 'NT11', ); { foreach my $inputData (@TestData) { my $outputData = $inputData; while (length($outputData) < 4) { $outputData .= '_'; } printf "%-4s -> %s\n", $inputData, $outputData; } } exit; __END__ C:\Steve\Dev\PerlMonks\P-2013-09-17@2038-Use-Strict>make4len.pl NT8 -> NT8_ NT9 -> NT9_ NT10 -> NT10 NT11 -> NT11

Replies are listed 'Best First'.
Re^2: How to have perl check line length
by ddrew78 (Beadle) on Sep 17, 2013 at 19:26 UTC
    Thank you, that did the trick.
      Here's a toy you might find useful:

      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
      You are most welcome, but I do advise that if you are going to maintain Perl code, it would be wise to examine the much more efficient mechanisms shown by other authors. Mine was designed to be readable; it is not exactly the most efficient way to do it in Perl. :-)

      That said, glad we could help.

        Apparently the code my company uses is so old, I tried the other suggestions as well, but couldn't get them to work. Also, I actually ended up modifying your code just a bit, specifically to this:
        open(NPBXNUM1, ">npbxnum1"); open(MYINPUTFILE, "npbxnum"); while (<MYINPUTFILE>) { my($line) = $_; chomp($line); foreach my $inputData ($line) { my $outputData = $inputData; while (length($outputData) < 4) { $outputData .= '_'; } print NPBXNUM1 "$outputData\n"; } } close(MYINPUTFILE); close(NPBXNUM1);
        Thanks again for the help.