Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

unerline or highlight keywords in a string

by rizzy (Sexton)
on Jun 09, 2011 at 18:43 UTC ( #908978=perlquestion: print w/replies, xml ) Need Help??
rizzy has asked for the wisdom of the Perl Monks concerning the following question:

I have some very long strings that I want to print to the screen and read through individually. In order to make it easier to read, I want to highlight (e.g., underline, bold, color, etc.) a few keywords.

Is there an easy way to do this without splitting up each string around every keyword and inserting formatting commands?

I think I can do a global replace of my keywords with the formatted keyword like so:

$mystring =~ s/keyword/formatted keyword/g; print "$mystring";

will this work, or will the print command interpret the formatting commands as plain text?

Also, is there a simple formatting command for bold or underline?

Replies are listed 'Best First'.
Re: unerline or highlight keywords in a string
by zek152 (Pilgrim) on Jun 09, 2011 at 19:52 UTC
      Thanks. I'm doing this on windows (don't ask). ANyway, I figured it out. I'm using:
      use Win32::Console::ANSI; use Term::ANSIScreen qw/:color /;

      and my substitution method works for that.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://908978]
Approved by mr_mischief
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2018-06-20 12:12 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (116 votes). Check out past polls.