Offer Kaye wrote:
Here are 2 other methods, just for the heck of it :-)
# Method 1
my $str = '[EMAIL PROTECTED]';
my ($part1,$part2) = split /@/, $str;
$part2 =~ s/_/./g;
$str = $part1."@".$part2;
print "$str\n";
# Method 2
my $str = '[EMAIL PROTECTED]';
while ($str =~ m/(?<=@).+?_/) {
$str =~ s/(?<=@)(.+?)_/$1./;
}
Using the same regular expression twice is redundant.
1 while $str =~ s/(?<=\@)(.+?)_/$1./;
print "$str\n";
Ram, there is just one thing you should notice - in your question, you
double-quote the string you assign to $str. You can't do that, because
the perl tries to evaluate the @lmn_p_q part as the name of an array.
So you either have to single quote the string (as John and I did) or
escape the @ sign with a backslash:
And yet in your examples you use @ in double quoted strings four times
without
escaping it (hint: m// and s/// interpolate like double quoted strings.)
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>