[Israel.pm] Perl Advocacy

Levenglick Dov-RM07994 DovL at freescale.com
Tue Dec 28 11:02:01 PST 2004

This is obviously an extremely ugly implementation, however (and I havent tested it) should do the job.

Call with a reference to the arrays/strings: str_replace(\(orig array), \(replace array or string), \$str);

sub str_replace {
	$orig = shift;
	$replace = shift;
	$str = shift;
	if (ref($replace) eq 'SCALAR') {
		$temp = join '|', @$replace;
		$$str =~ s/($temp)/$$replace/g;
	else {
		if (scalar(@$orig) > scalar(@$replace) {
			push (@$orig), '' for (scalar(@$orig) > scalar(@$replace);
	for (0..(scalar(@$orig)-1) {
		$$str =~ s/$$orig[$_]/$$replace[$_]/g;

Best Regards,
Dov Levenglick
The information contained in this email is classified as:
[ ] General Business Information
[ ] Freescale Internal Use Only
[ ] Freescale Confidential Propriety
[x] Personal Memorandum

-----Original Message-----
From: perl-bounces at perl.org.il [mailto:perl-bounces at perl.org.il] On Behalf Of david istermann
Sent: Tuesday, December 28, 2004 8:43 PM
To: Perl in Israel
Subject: Re: [Israel.pm] Perl Advocacy


mixed str_replace (mixed search, mixed replace, mixed subject);

If -subject- is an array, then the search and replace is performed
with every entry of -subject-, and the return value is an array as

If -search- and -replace- are arrays, then str_replace() takes a value
from each array and uses them to do search and replace on -subject-.
If -replace- has fewer values than -search-, then an empty string is
used for the rest of replacement values. If -search- is an array and
-replace- is a string; then this replacement string is used for every
value of -search-.

Perl mailing list
Perl at perl.org.il

More information about the Perl mailing list