I think your format string for the unknown is a bit off.
Here is my example:
foreach $longitude (1,2.12345678,undef) { if (defined $longitude){ printf ("|%-8s %.6f|\n","",$longitude); }else{ $longitude2 = "<unknown>"; printf ("| %16s|\n",$longitude2); } }
And the output (with " %16s" for an unknown format. I added vertical columns to clearly see the alignment):
| 1.000000| | 2.123457| | <unknown>|
PS If you look at your pattern matching and what you created, then the <unknown> state also seems to be misaligned. To check, use the same trick I did above, including the format string for each field in | to see where one field ended and another begins.
source share