http://www.perlmonks.org?node_id=667229


in reply to Escape characters with FORMAT?

You have to read all the way to the last paragraph of perlform

Within strings that are to be displayed in a fixed length text field, each control character is substituted by a space. (But remember the special meaning of "\r" when using fill mode.) This is done to avoid misalignment when control characters "disappear" on some output media.

It works just fine with a variable length field, but that's probably not very useful for you...

#!/usr/bin/perl use strict; use warnings; my $Status="\033[32mSTATUS\033[0m"; my $ms = 6; my $count = 42; format STDOUT = ^<<<<< ^<<<<< @* $ms, $count, $Status . write STDOUT;

My advice: If you are dealing with a single line format, just use sprintf instead.

UPDATE: Actualy your "data" probably doesn't have control characters in it right? you're just trying to shove control characters into it -- what you relaly want is for your format to have control characters in it. While that's not possible, you can use variable width fields that you know will always get filled with 0 length values (which just happen to be control characters...

#!/usr/bin/perl use strict; use warnings; my $Status="STATUS"; my $ms = 6; my $count = 42; my $START_COLOR = "\033[32m"; my $CHANGE_COLOR = "\033[36m"; my $END_COLOR = "\033[0m"; format STDOUT = ^<<<<< @* ^<<<<<< @* ^<<<<<<<<<<<<< @* $ms, $START_COLOR, $count, $CHANGE_COLOR, $Status, $END_COLOR . write STDOUT;