newbie question on output formatting/"pretty" print

Discussion in 'Perl Misc' started by martin, Apr 17, 2006.

  1. martin

    martin Guest

    Hi, I am trying to print to a file 3 columns of information, the first
    row is the label field,
    consisting of 3 strings, 9, 4, and 9 characters wide. The first column
    is strings, the second and third are integrs, of 1 up to 14 digits
    wide.

    aaaaaaaaa bbbb ccccccccc
    --------------- ------- ---------------
    xxxxxxxx 1 43432
    xxxxxxxx 3213213 435435435
    so on

    I tried with printf %s and %d (- and + options also) but since the
    width of second and third columns varies widely, the result is not
    appealing and it needs a lot of trial and error to get something
    half-decent looking. And also there seems to be no center
    justificiation option with
    printf.

    I am wondering is there a way to get a decent print display without
    too much trial and error. and juggling of fields nad printf options.
    Thanks. Martin
    martin, Apr 17, 2006
    #1
    1. Advertising

  2. A. Sinan Unur, Apr 17, 2006
    #2
    1. Advertising

  3. martin

    Ian Wilson Guest

    martin wrote:
    > Hi, I am trying to print to a file 3 columns of information, the first
    > row is the label field,
    > consisting of 3 strings, 9, 4, and 9 characters wide. The first column
    > is strings, the second and third are integrs, of 1 up to 14 digits
    > wide.
    >
    > aaaaaaaaa bbbb ccccccccc
    > --------------- ------- ---------------
    > xxxxxxxx 1 43432
    > xxxxxxxx 3213213 435435435
    > so on
    >
    > I tried with printf %s and %d (- and + options also) but since the
    > width of second and third columns varies widely, the result is not
    > appealing and it needs a lot of trial and error to get something
    > half-decent looking. And also there seems to be no center
    > justificiation option with
    > printf.
    >
    > I am wondering is there a way to get a decent print display without
    > too much trial and error. and juggling of fields nad printf options.


    I still have a soft spot for Perl's "write" function, which handles
    centering and column-wrap nicely.
    (see `perldoc perlform`)
    Ian Wilson, Apr 18, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew Montgomery
    Replies:
    0
    Views:
    602
    Andrew Montgomery
    Sep 17, 2003
  2. Christian Ashby

    Pretty Printing / Code formatting for JSPs

    Christian Ashby, Aug 20, 2004, in forum: Java
    Replies:
    0
    Views:
    356
    Christian Ashby
    Aug 20, 2004
  3. Alan G Isaac

    pretty print 2D arrays

    Alan G Isaac, Aug 12, 2004, in forum: Python
    Replies:
    1
    Views:
    534
    Colin J. Williams
    Aug 13, 2004
  4. keto
    Replies:
    0
    Views:
    879
  5. Jason
    Replies:
    4
    Views:
    198
    Dr J R Stockton
    Nov 21, 2009
Loading...

Share This Page