Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
$message_ref->[0] contains a number between 1 and 100 and possibly some other text.I want this number to be replaced by the equivalent text listed in %method. However if the number is 23, and the for loop yields a key equal to 2 then $message_ref->[0] becomes equal to the text equivalent to 2 with the 3 at the end. Does anyone know how I can ensure 23 will only be replaced with 23's text and not 2's? Any help at all would be greatly appreciated ASAP Cheers.foreach $key (keys %method) { $message_ref->[0]=~s/$key/$method{$key}/; }
Edit: Added <code> tags. larsen
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Matching and replacing
by benn (Vicar) on Mar 25, 2003 at 14:00 UTC | |
|
Re: Matching and replacing
by davorg (Chancellor) on Mar 25, 2003 at 14:02 UTC | |
|
Re: Matching and replacing
by robartes (Priest) on Mar 25, 2003 at 17:13 UTC |