James Edward Gray II <[EMAIL PROTECTED]> wrote: : : On Feb 23, 2004, at 5:14 PM, David le Blanc wrote: : : >> -----Original Message----- : >> From: Hanson, Rob [mailto:[EMAIL PROTECTED] : >> Sent: Tuesday, 24 February 2004 5:43 AM : >> To: 'Olivier Wirz'; [EMAIL PROTECTED] : >> Subject: RE: substitution : >> : >>> Is it possible to do this : >> : >> No, at least not the way you are doing it. : >> : >> Something like this will work (untested) : >> : >> my %replacements = (ARE => 756, TYP => 978, SPE => 840); : >> $marque =~ s/(ARE|TYR|SPE)/$replacements{$1}/; : > : > Close, you need the /e option to enable evaluation of the : > replacement string, and /g for good measure. : > : > my %replacements = (ARE => 756, TYP => 978, SPE => 840); : > $marque =~ s/(ARE|TYR|SPE)/$replacements{$1}/eg; : : Huh? The replacement string will interpolate variables without an /e : modifier just fine, I promise. Try it. ;)
James has it right. Though I think I would disagree with Rob and use this to aid maintainability: for ( $marque ) { s/ARE/756/g; s/TYR/978/g; s/SPE/840/g; } HTH, Charles K. Clarkson -- Mobile Home Specialist 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>