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

edimusrex has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks, I am attempting to print every other line of output in color using Term::ANSIColor and printf. I have managed to sort of pull off what I am trying by the following code

my $c = 0; printf("\n%-7s %-22s %-18s %-35s %-15s %-16s %-30s\n\n", "ID","MAC","I +P","Manufacturer","Authorized","Acknowledged","Notes"); while(@row = $sth->fetchrow_array){ my ($id,$mac,$ip,$man,$auth,$ack,$notes) = @row; push @device_ids, $id; if ($c == 1){ printf( "%-7s %-22s %-18s %-35s %-15s %-16s %-30s\n", colored("$id", 'bold blue on_grey10'), colored("$mac", 'bold blue on_grey10'), colored("$ip", 'bold blue on_grey10'), colored("$man", 'bold blue on_grey10'), colored("$auth", 'bold blue on_grey10'), colored("$ack", 'bold blue on_grey10'), colored("$notes", 'bold blue on_grey10'), ); $c--; } else{ printf("%-7s %-22s %-18s %-35s %-15s %-16s %-30s\n", "$id" +,"$mac","$ip","$man","$auth","$ack","$notes"); $c++; } $cnt++; }

but what seems to happen when I run it is the printf formatting is not applied. I'd like the entire row to be highlighted and formatted not just the individual fields (so the spaces too).


As always, thanks for the help in advanced