[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: OT: Why is C so popular?



bob parker wrote:

C is easier to learn than shell scripting, the elements at least, much less

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.


Another 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++:

$email_in = 'Anawalt, Jacob; <jacob@cachevalley,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 username@domain portion of the email
if($email_out =~ /([$vc][$vc$vu]*)\@([$vc$vd]*[$vc])?/) {
  #Match worked, email is just username@domain portion
$email_out = "$1\@$2"; #$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 jacob@cachevalley.com.

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



Reply to: