Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Re: Re: Converting CSV files to fixed width flat files

by graff (Chancellor)
on May 28, 2003 at 01:55 UTC ( [id://261173]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Converting CSV files to fixed width flat files
in thread Converting CSV files to fixed width flat files

To the best of my knowledge, printf (and sprintf) will never truncate a field that is too long for the width specified in the format string -- it will always provide each field with as many characters as needed to fit a given string with "%s" or all digits with "%d", or all digits to the left of the decimal point with "%f", thereby screwing up the programmer's intended vertical alignment of fields on successive lines, rather than eliminate significant data that would not have fit the programmer's margins.

update: thanks to PodMaster for some much needed tutoring... my comments above did not consider format specs that really do impose field truncation, like "%1.1s" -- I was only thinking of the more common flavor, like "%1s", which does not truncate. (I still don't know how to truncate numerics...)

  • Comment on Re: Re: Re: Converting CSV files to fixed width flat files

Replies are listed 'Best First'.
Re: Re: Re: Re: Converting CSV files to fixed width flat files
by PodMaster (Abbot) on May 28, 2003 at 02:03 UTC
    To the best of my knowledge, printf (and sprintf) will never truncate a field that is too long for the width specified in the format string
    s?printf does what you tell it  printf "%1.1s$/", 'foy'; yields 'f',  printf "%s$/", 'foy'; yields 'foy'. As for Limbic~Regions note, you can't convert variable width "records" to fixed width ones without possibly undergoing some truncation ;)


    MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
    I run a Win32 PPM repository for perl 5.6x+5.8x. I take requests.
    ** The Third rule of perl club is a statement of fact: pod is sexy.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://261173]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-25 22:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found