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

I am a newbie,just out of the emergency room, so please forgive. I have a text document that I must parse and send as a message in an email. My problem is that I need one of the words to be italicized, but I cant get it to work. I read a recent post with a similiar problem, however that was for converting it to a word document and thats not what I want. If you can help, I would appreciate it greatly

Replies are listed 'Best First'.
Re: italicize an email message
by jasonk (Parson) on Apr 09, 2003 at 14:32 UTC

    You have to convert it to some form of document that includes fonts, because email is ascii-based and has no concept of italics.


    We're not surrounded, we're in a target-rich environment!
Re: italicize an email message
by Tomte (Priest) on Apr 09, 2003 at 14:43 UTC

    depending on the recipient and theyre internet-background or geekiness: using slashes to italicize a word in an ascii message (like /so/) could be understood (and asterisk to signal *bold*)...

    these were the days...

    regards,
    tomte


    Hlade's Law:

    If you have a difficult task, give it to a lazy person --
    they will find an easier way to do it.

Re: italicize an email message
by Improv (Pilgrim) on Apr 09, 2003 at 14:38 UTC
    Depending on your email client, you might just cut'n'paste it into a MIME/HTML capable mail client, and then highlight the word in there and click on the italics button. Of course, a lot of people, myself included, dislike recieving HTML mail. There are various modules that you might use to do this programmatically. One way might be to just set the mime type to text/html using the provided APIs, enclose the message text in a <PRE> tag, and then enclose the needed word in <I>WORD<\I>
    You might find these particular modules helpful:
    MIME::Body
    MIME::Light
    MIME::Entity

    MIME::Light will probably be the most useful.
Re: italicize an email message
by Coplan (Pilgrim) on Apr 09, 2003 at 16:37 UTC
    Just one word? Regexp is your solution. I assume you're using HTML output?
    open(FILE, "file.txt") or die "$!"; while (<FILE>) { $_ =~ /$word/<em>$word</em>/; } print $_; close(FILE);
    Disclaimer: This code hasn't been tested!

    --Coplan

      perhaps  $_ =~ /$word/<em>$word</em>/; should be   $_ =~ s/$word/<em>$word</em>/;

      feanor_269

        Well ... it should be $_ =~ s/\Q$word\E/<em>$word</em>/g;

        Jenda
        Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
           -- Rick Osborne

        Edit by castaway: Closed small tag in signature

      I'm not using HTML as my output....I'm not sure exactly how or why I should? Let me explain a little better my problem. There is this mass email that has to be sent out to various people within my company. The message I have to send has a word that needs to be italicized. I am using NET::SMTP to send the email so the message is just text. thanks again

        That's the point others are trying to make: you can't use italics in a plain text message. To do so, you either need HTML, or RTF, or something similar. You can send a multipart email using MIME, but again, the plain text portion will not have any font formatting, only the HTML or RTF portion.