Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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


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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

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







    Results (72 votes). Check out past polls.

    Notices?