in reply to Escape characters with FORMAT?

The code you provide doesn't (can't) generate the output you suggest it does - at the very least the width of the last field doesn't allow the text '1.24ms' to be generated.

I'd use printf instead of format. Maybe something like:

use strict; use warnings; my $status = 'frst'; my $element = 'tyr'; my $Status = "\033[32m$status"; my $Element = "\033[36m$element"; my $ms = '0ms'; my $count = '1.24ms'; my $format = " %-4s %-18s %-7s %-3 +s\n"; printf $format, $Status, $element, $ms, $count;

Prints:

frst tyr 0ms + 1.24ms

Note that there is an escape character before the first [


Perl is environmentally friendly - it saves trees

Replies are listed 'Best First'.
Re^2: Escape characters with FORMAT?
by dayton (Acolyte) on Feb 10, 2008 at 18:40 UTC
    Thanks, printf works perfectly.