in reply to Re^4: How to have perl check line length
in thread How to have perl check line length
You went through the effort of specifying > on the output file; consistency has much value in engineering. Why not boldly include the < on the input file?open(NPBXNUM1, ">npbxnum1"); open(MYINPUTFILE, "npbxnum");
And I'm sure other Monks would strongly recommend breaking the < and > out into their own parameters, for reasons I don't pretend to understand:open(NPBXNUM1, ">npbxnum1"); open(MYINPUTFILE, "<npbxnum");
open(NPBXNUM1, '>', "npbxnum1"); open(MYINPUTFILE, '<', "npbxnum");
probably better as:while (<MYINPUTFILE>) { my($line) = $_; chomp($line);
while (my $line = <MYINPUTFILE>) { chomp($line);
The foreach loop is pointless, as its purpose is to iterate through an array; $line is a scalar.foreach my $inputData ($line) { my $outputData = $inputData; while (length($outputData) < 4) { $outputData .= '_'; } print NPBXNUM1 "$outputData\n"; }
Perhaps better as:
my $outputData = $line; while (length($outputData) < 4) { $outputData .= '_'; } print NPBXNUM1 "$outputData\n"; }
|
|---|