How do you make a word or pattern *bold* by using the substitution.
Is it possible to do this in Perl?
>How do you make a word or pattern *bold* by using the substitution.
>Is it possible to do this in Perl?
Perl doesn't know anything about bold. Perhaps this is a TeX question?
if you explain what you are trying to do (the big picture, not the fine
detail) someone might be able to help. :)
--
brian d foy <com...@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)* <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
$paragraph =~ s#$word#<b>$word</b>#gs;
John Robson wrote:
>
> How do you make a word or pattern *bold* by using the substitution.
> Is it possible to do this in Perl?
--
---------------------------------------------------
Michael Cornelio
I can eat SPAM, but don't like to read the stuff.
Remove NOSPAM from my email address to reply to me.
brian d foy (com...@computerdog.com) writes:
> In article <62351b$a...@freenet-news.carleton.ca>, as...@FreeNet.Carleton.CA (John Robson) wrote:
>
>>How do you make a word or pattern *bold* by using the substitution.
>>Is it possible to do this in Perl?
>
> Perl doesn't know anything about bold. Perhaps this is a TeX question?
> if you explain what you are trying to do (the big picture, not the fine
> detail) someone might be able to help. :)
I'm trying to search for a word in a text file and then change that word
to bold. More precisely, print the line containing the word on the screen,
but show the word in BOLD. I'm thinking maybe there is some kind of
special ASCII code in MS-DOS or Unix that you can substitute to make
something look "bold" or "underlined". How does a word processor do it
anyway? How does a word processor translate from one document format to
another and still preserve the word attributes? Maybe it's not a Perl
question, but if Perl can do it, I'll be happy! :)
With a DEC VT-terminal (ANSI terminal or any display
environment supporting ANSI escape codes) you'd send
CSI1m
or
ESC[1m
to turn bold on and
CSI22m
or
ESC[22m
to turn it off.
CSI is the Control Sequence Introducer (decimal value
155) and ESC[ is its 7-bit equivalent (the escape
character - decimal 27 - followed by the '[' character
(dec 91).
Example translation to Perl:
my $CSI = "\x1B\x5B
my $boldon = "$CSI1m";
my $boldoff = "$CSI22m";
print "Bold stuff: $boldonThis is bold!$boldoff";
(Not tested ;-).
That won't work on a graphics/bitmapped terminal/display
(such as under MS Windows*, the MacOS or an X Window
System environment). There'd you'd select a bold
variation of the current font using a suitable system/
library call or somesuch...
regards,
...petri.b...@icl.fi
ICL Data Oy
Finland
Yup, you're right, it's not a Perl question. A "text" file per se does
not
know anything about "bold" or "italic" or anything else. Text is text.
There is no generlized, standard way to make things bold.
Some text files happen to be HTML files, and in HTML you can surround
<b>important text</b> with HTML markup tags. Other text files happen
to be
RTF files an you can mark {\b screaming headlines} with markup tags as
well.
Postscript files are also basically text, and postscript uses its own
kind of tag. There are actually all kinds of text formats and markup
codes.
Then there are binary file formats, such as MS-Word *.doc files,
or WordPerfect files. Each of these formats probably uses its own
proprietary way of storing information about text formatting.
The reason word processing applications can understand each other's
encoding is because the manufacturers explicitly write converters,
which convert files from one format into another. Sometimes these
converters do their work behind your back, without you seeing them.
All you see is the result. But somehow, on some level, formatting
information like bold and italics are stored in some way.
If you want to cobble your own code for making things bold, it might
be pretty easy. But you need to know how "bold" is encoded in your
particular application. If it's HTML, then write code to insert
"<B>" and "</B>" into your text. If you're writing DOS batch programs
and you want to make bold or blinking text on your PC monitor,
then you need to insert special escape characters, which are specific
to PC's. If you don't know, your best bet is to find a newsgroup
which specializes in the application you're using.
Once you find out, then you can use Perl to write the code.
It just so happens that Perl is particularly good at manipulating
text in this way. :)
-John Nolan
i do the following :-
on unix
$HIGH = `tput bold` # puts escape codes for bold into var HIGH.
## `tput smul` for underline, `tput rev` for reverse-video
$NORM = `tput rmso` # codes to restore normal mode.
or if on a color_xterm
$HIGH = "\033[00;32m"; # the 32 gives green, 31 red , 34 blue ....
$NORM="\033[0m";
on MSDOS similar to color_xterm
$HIGH = "\033[1;32m";
$NORM="\033[0m";
then something like this in my perl script :-
print if s/${word}/${HIGH}$&${NORM}/ ;
--
Gerald K. Embery ; e-mail: G.Em...@BoM.GOV.AU ; URL=http://www.BoM.GOV.AU/
Bureau of Meteorology Research Centre, Melbourne, Australia ;
Disclaimer: These are *my* opinions, *not* those of my employer..... [ my employer has no opinions.... ;-) ] ;
"It's ugly but it works!" ... old BMRC saying ...