Re: [MacPerl-AnyPerl] singlesqoutes <-> doubleqoutes

[email protected] (Bart Lateur) Mon, 23 Jul 2001 13:29:53 +0200
Newsgroups perl.macperl.anyperl
Organization MediaMind
Message-ID <[email protected]>
On Fri, 20 Jul 2001 22:08:13 +0200, allan wrote:

>my $str = qq(this word should have 'doubleqoutes' and this should have "singleqoutes");
>
>$str =~ s/'/some_temp_for_singles/g;
>$str =~ s/\"/some_temp_for_doubles/g;
>$str =~ s/some_temp_for_singles/"/g;
>$str =~ s/some_temp_for_doubles/'/g;
>print "OK: ", $str;

If tr/// were not available... or if you want to replace longer strings,
like replacing "ab" with "ba" and vice versa:

There's no reason in Perl to do any replacement in multiple passes. Use
the combination of s/// with a replacement hash.

	%replace = ( "\"" => "'", "'" => "\"");
	s/(['"])/$replace{$1}/g;

-- 
	Bart.