Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

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?

Comment on unerline or highlight keywords in a string
Download Code
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://908978]
Approved by mr_mischief
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (12)
As of 2015-07-07 22:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls