C is easier to learn than shell scripting, the elements at least, much lessAnother great example on why the variety is a good thing. I agree on the C vs shell. The only way I write shell scripts is by example. I don't understand it well enough to write a script from a blank page. On the otherhand, I _so_ find myself wishing I could use regexp's this way in C/C++:
Perl. I personally find it quicker to code a dirty fix in C than anything else and would not really consider shell programming for anything other than glue for a sequence of other commands.
Just my 2 bits.
$email_in = 'Anawalt, Jacob; <[EMAIL PROTECTED],com>; runme&'; $vc = 'a-zA-Z0-9'; #Valid username and domain characters $vd = '.-'; #Valid domain non-characters $vu = $vd . '_'; #Valid username non-characters (domain plus an underscore)
$email_out = $email_in; $email_out =~ s/,/./g;
# Look for just the [EMAIL PROTECTED] portion of the email
if($email_out =~ /([$vc][$vc$vu]*)\@([$vc$vd]*[$vc])?/) {
#Match worked, email is just [EMAIL PROTECTED] portion
$email_out = "[EMAIL PROTECTED]"; #$1 and $2 are the patterns \1 and \2 matched from the regexp
} else {
#Match failied, empty string;
$email_out = '';
}
print "$email_out\n"; #Prints [EMAIL PROTECTED]
If somone else is happier writing a cool class and some loops or figuring out a C++ regexp class to do this, or just some adept use of C string library calls, more power to you. :)
Jacob
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]