email email email

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
samip1983
Forum Newbie
Posts: 7
Joined: Thu Jul 28, 2005 9:57 am

email email email

Post by samip1983 »

Hi all,

was jus playing with some code i need to manipulate email address, this is just the beginning part. I need once the email is entered a switch is also used. U means upper case. WC means for all the . to be changed to / dot / and the @ changed to / at /.
The next switch is wc and does the reverse of the WC switch. This doesnt seem to work at all. and its buggin me.

Code: Select all

#!/usr/bin/perl
use strict;
use CGI ':standard';

my ($email, $switch, $up);

$email = param('email');
$switch = param('switch');

$up = uc($email);

print "content-type: text/html\n\n";

if (($email) && ($switch =~/U/)) {
print "$up\n";
}

elsif (($email =~ s/\./ dot /g) && ($email =~ s/\@/ at /g) && ($switch =~ /WC/)) {
print "$email\n";
}

elsif (($email =~ s/ dot /\./g) && ($email =~ s/ at /\@/g) && ($switch =~/wc/)) {
print "$email\n";
}
Any help would be great

Thanks

Sami P

d11wtq | fixed U ==> U ;)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

I haven't tested but this should work. You should stop using regex to check for a static string (the regex were validating something like "UUUGGAFAGSH" as if it was "U"...)

Code: Select all

#!/usr/bin/perl
use strict;
use CGI ':standard';

my ($email, $switch, $up);

$email = param('email');
$switch = param('switch');

$up = uc($email);

print "content-type: text/html\n\n";

if ($email && $switch eq "U") {
print "$up\n";
}

elsif (($email =~ s/\./ dot /g) && ($email =~ s/\@/ at /g) && $switch eq "WC") {
print "$email\n";
}

elsif (($email =~ s/ dot /\./g) && ($email =~ s/ at /\@/g) && $switch eq "wc") {
print "$email\n";
}
samip1983
Forum Newbie
Posts: 7
Joined: Thu Jul 28, 2005 9:57 am

Post by samip1983 »

Hi,

thnaks for your reply.

Some of the code works fine, the bit that doesnt work is if the $email is for example 'x dot x at hotmail dot com', the wc switch does not seem to be changing the email to 'x.x@hotmail.com', cant seem to put my finger on the problem.
My initail thought is the space in the regex, becase when entering U as a switch and the $email is 'x dot x at hot.......' the result is just a 'X'

Any ideas??

thanks
Post Reply