emcb has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
I have written a sub called str_replace. This sub is supposed to work the same as the php function str_replace. Heres the code:
sub str_replace
{
my( $find,$replace,$what ) = @_;
$what =~ s/$find/$replace/i;
return $what;
}
I then use this function to find x and replace it with y in z like so:
$string = str_replace("Hi", "Hello", "Hello My Name Is Elfyn");
This function only returns 'Hi' instead of 'Hi My name Is Elfyn'. Any help on why fellow monks.
Cheers,
Elfyn
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: dodgy sub
by strat (Canon) on Feb 27, 2002 at 13:43 UTC | |
|
Re: dodgy sub
by broquaint (Abbot) on Feb 27, 2002 at 13:42 UTC | |
|
Re: dodgy sub
by dragonchild (Archbishop) on Feb 27, 2002 at 14:55 UTC | |
by emcb (Beadle) on Feb 27, 2002 at 15:45 UTC |