in reply to How to align tabbed strings?

As WizardOfUz has said, Text::Table will do as you want (and a whole lot more). Perhaps a simpler solution using printf (the formatting codes are described in sprintf) will do:
my @rows = ( [qw/johnny 2 12-09-2008/], [qw/rob 2 25-10-2008/], ); my $format = "%-8s %-5s %-8s\n"; printf $format, qw/Username Level Created/; printf $format, @$_ for @rows; __END__ Username Level Created johnny 2 12-09-2008 rob 2 25-10-2008


Unless I state otherwise, all my code runs with strict and warnings

Replies are listed 'Best First'.
Re^2: How to align tabbed strings?
by Anonymous Monk on Jan 02, 2010 at 17:49 UTC

    Wonderful, thank you so much!

    Instead of printing, is it possible to save the formatted string into a variable (scalar), so that you can send it off (for instance) as a message in email (via sendmail)?

      That's what sprintf does!

      my $format = "%-8s %-5s %-8s\n"; my $output = sprintf $format, qw/Username Level Created/; $output .= sprintf $format, @$_ for @rows;