topical media & game development

talk show tell print

basic-regex-10-JimOrFred.pl / pl



  #!/usr/bin/perl -w
  use strict;
  print "This program will say 'Hello' to Jim or Fred.\n";
  my myPattern = "^(Jim|Fred)$";
  # The pattern matches only 'Jim' or 'Fred'. Nothing else is allowed.
  print "Enter your first name here: ";
  my myTestString = <STDIN>;
  chomp (myTestString);
  if (myTestString =~ m/myPattern/x)
  {
   print "Hello myTestString. How are you today?";
  }
  else
  {
   print "Sorry I don't know you!";
  }


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.