Twokinds ARCHIVE Forums

This forum is for the preservation of old threads from before the forum pruning.
It is currently Wed Apr 30, 2025 3:44 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Code Snippets
PostPosted: Tue Feb 21, 2006 10:57 pm 
Offline
Templar Inner Circle
User avatar

Joined: Wed Mar 09, 2005 1:55 am
Posts: 2885
Location: Somewhere in my pants.
Here is a place to post useful and reusable code that you would like to share. Keep it trimmed, only the necessar parts, and if need be, give a description of how to integrate it into a project(and even an example if you can), and keep the code in the [ code] and [/ code] tags(without spaces. :P). Be sure to include the language. :D

Here's one to start:
It's a simple email validity checking subroutine written in Perl, which uses a regular expression to check and make sure that it resembles a valid email.
Code:
sub checkemail {
   my $email = shift;
   my @exts = ("com", "org", "net", "info");
   foreach (@exts) {
      if ($email =~ /^(.+)[@](.+[.]$_)/) {
         print ("Valid email address entered. ($email)\n");
         print ("Username is $1.\n");
         print ("Hostname is $2.\n");
         exit (0);
      }
   }
   print ("Please enter a valid email address.\n");
}

An example of how to use it would be:
Code:
sub checkemail {
   my $email = shift;
   my @exts = ("com", "org", "net", "info");
   foreach (@exts) {
      if ($email =~ /^(.+)[@](.+[.]$_)/) {
         print ("Valid email address entered. ($email)\n");
         print ("Username is $1.\n");
         print ("Hostname is $2.\n");
         exit (0);
      }
   }
   print ("Please enter a valid email address.\n");
}
my $em = $ARGV[0];
checkemail($em);

Enjoy. :D

Note: Spam this thread and what will follow will be the most violent e-beating of a person ever recorded in history. :D


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group