in reply to Seeking fixed length
An important addition to the use of (s)printf because it is not used everyday (but you can read it in the excellent tutorial Using (s)printf() by reptile). In order to enforce a field width of e.g. 3 for a string you have to use:
Just using %3s does not enforce the maximum length of the field - and btw pack doesn't have these 'problems'.printf "%3.3s\n", 'Ho'; printf "%3.3s\n", 'Hogfather' printf "%3s\n", 'Hogfather'; # this prints Ho Hog Hogfather
Update: Of course maybe it's not such a good idea to silently throw away part of the fields - so you should check the length of them beforehand. But this depends on your purpose ...
-- Hofmator
|
|---|