Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Printing alternating lines in color with printf and Term::ANSIColor

by toolic (Bishop)
on Oct 06, 2016 at 15:36 UTC ( #1173412=note: print w/replies, xml ) Need Help??


in reply to Printing alternating lines in color with printf and Term::ANSIColor

Format your line before coloring it. This works for me:
use warnings; use strict; use Term::ANSIColor qw(colored); my $c = 0; my $fmt = '%-7s %-22s %-18s %-35s %-15s %-16s %-30s'; printf "$fmt\n", qw(ID MAC IP Manufacturer Authorized Acknowledged Not +es); for (1..4) { my @row = 1..7; my ($id,$mac,$ip,$man,$auth,$ack,$notes) = @row; my $str = sprintf $fmt, $id,$mac,$ip,$man,$auth,$ack,$notes; if ($c == 1) { print colored($str, 'bold blue on_grey10'), "\n"; $c--; } else{ print "$str\n"; $c++; } }
  • Comment on Re: Printing alternating lines in color with printf and Term::ANSIColor
  • Download Code

Replies are listed 'Best First'.
Re^2: Printing alternating lines in color with printf and Term::ANSIColor
by edimusrex (Monk) on Oct 06, 2016 at 15:45 UTC

    Perfect! Thank you, works like a charm

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2021-10-19 14:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (77 votes). Check out past polls.

    Notices?