Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Escape characters with FORMAT?

by hossman (Prior)
on Feb 10, 2008 at 04:47 UTC ( #667229=note: print w/replies, xml ) Need Help??


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;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://667229]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2020-07-09 21:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?