adjusting characters in a field

Status
Not open for further replies.

ranjeeth

Newbie level 6
Joined
Aug 3, 2005
Messages
13
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Mumbai,India
Activity points
1,469
C uses "%6.2f" etc to align numbers properly ? Can it be done with characters in PERL i.e adjusting a group of characters within a field so as to have proper alignment for eg I wish to adjust and align an array of characters into a field of say 10.
 

You may use printf in perl as in C.
 

    ranjeeth

    Points: 2
    Helpful Answer Positive Rating
Hi ,
i think i need to frame my question properly , i wish to align characters and not numbers.
for eg given strings Jane Joe Mary etc i wish to store these strings as strings of 10 characters ,the trailing characters being spaces. is there a standard perl function for doing this.
 

Replace the format character f to s: "%-10s"
 

    ranjeeth

    Points: 2
    Helpful Answer Positive Rating
Perl's sprintf() does string formatting too.
**broken link removed**

Sound like you want "%-10.10s" or "%-10s". The first one truncates to 10 characters.
 

    ranjeeth

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…