Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Print Color Format

by toolic (Bishop)
on Jun 16, 2015 at 17:35 UTC ( [id://1130651]=note: print w/replies, xml ) Need Help??


in reply to Print Color Format

use warnings; use strict; use Term::ANSIColor; my @field = 1..6; my @fmts = qw(%-4s %-11s %-13s %-10s %-7s %0s); my @cols = qw(green red green red green red); # Fill in your colors he +re for my $i (0 .. $#field) { print color($cols[$i]); printf $fmts[$i], $field[$i]; } print color('reset'), "\n";

Replies are listed 'Best First'.
Re^2: Print Color Format
by PilotinControl (Pilgrim) on Jun 16, 2015 at 18:02 UTC

    Thanks toolic!
    your code works as is, however when I insert a split code, which removes ":" from each field from the data file, I received an "uninitialized value for $_" error? I am confused as to why that is? Thoughts? Thanks!

        Good webpage..never seen it before thanks. I should of posted more code including the "split" section.

        foreach my $Name2 (@lines) { my @field = split(':',$Name2); if ($field[1] =~ /(?<![\w-])$Name(?![\w-])/i) { my $format = " %-4s %-11s %-13s %-10s %-7s %0s\n"; print color 'bold green'; printf ($format, $field[0], $field[1], $field[2], $field[3], $field[4] +, $field[5]); } }

        Complete Code

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (8)
As of 2024-03-28 12:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found