in reply to Possible to use variable in printf statement?
my @colLength; sub calcMaxColumn { # $i will hold index locations of column lengths in the array @co +lLengths. my $i; # Loop through the array @AoA. And if the length of the current c +olumn is greater then the length of the # same column in the previous row then set the greater number equ +al to that location in @colLength. for (my $x = 0; $x <= $#AoA; $x++) { $i = 0; for (my $y = 0; $y <= 11; $y++) { if ($colLengths[$i] < length($AoA[$x][$y])) { $colLengths[$i] = length($AoA[$x][$y]); } $i++; } } }
my $strLen = 0; for (my $x = 0; $x <= $#AoA; $x++) { #If the current line is an owner then there will only be 10 el +ements. if ($AoA[$x][0] eq 'OWNER') { $waitline = 10; } #ELSE the line is a user waiting and we should add the time wa +iting to the end of that line, 11 total elements. else { $waitline = 11; } for (my $y = 0; $y <= $waitline; $y++) { $strLen = $colLengths[$y]; printf OUTDATA "%-${strLen}s ", $AoA[$x][$y]; } print OUTDATA "\n"; }
|
|---|