Jump to content

Colored text in perl


Recommended Posts

I'm not a perl programmer, but I know that the syntax is very similar to bash. To print text in red color do:

 

 ~$ cat colors.pl
#! /usr/bin/perl
# shows output in red
$red="\e[1;31m";
$normal="\e[0m\n";

print "$red This is a text $normal";

 

Some time ago I wrote this function for my own bash library, so you may use it to find out which are the strings that define each color:

 

 

:

# listado de colores terminal.

 

colores ()

{

    normal="\\033[0;39m";

    for j in 0 1;

    do

        for i in $(seq 30 36) $(seq 43 47);

        do

            color="\\033[${j};${i}m";

            echo -ne "${color}\\\\\\${color}";

            echo -e "$normal";

        done;

    done;

    echo -ne "\n${normal}\\\\\\${normal} NORMAL\n"

}

 

colores

 

 

Copy the above text into a file and run it, it will show you the different keys for each color. Then you'll only need to translate them into perl format.

 

 

HTH

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...