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

I need to remove chevrons <> from my variables in the script before i print them to a file. I am writing out an XML file and I need them gone. How would i do that...
Example

$subj = $head->get('Subject');
$from = $head->get('From');
$to = $head->get('to');
$cc = $head->get('cc');
$recipients = $head->get('recipients');
So the CC, from, and To headers have chevrons in them. Just want to blank them out or replace them with & l t ; & g t ;
Please help this is driving me crazy!!!

Replies are listed 'Best First'.
Re: remove chevrons from an email address
by chromatic (Archbishop) on Feb 14, 2005 at 23:05 UTC

    I like to use Email::Address for manipulating addresse. Does the address() method do what you want?

    As a side note, why does your XML formatting module not encode entities appropriately? I recommend filing a bug with the author. You oughtn't have to think about escaping things, be they XML-significant characters, entity references, or Unicode characters. (Have you tried XML::Writer?)

Re: remove chevrons from an email address
by sh1tn (Priest) on Feb 14, 2005 at 23:11 UTC
    Rough example:
    $subject = '<sm.th.>'; $regex = { '<', '&lt', '>', '&gt' }; for( keys %$reg ){ $subject =~ s/$_/$reg->{$_}/g }