Perl Topics





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
Perl Tutorial
Introduction Introduction
Installing Perl Installing Perl
Basics of Perl Basics of Perl
Scalar Variables Scalar Variables
Operators Operators
Control Structures Control Structures
Lists Lists
Array Array
Arrays Manipulation Arrays Manipulation
Arrays Functons Array Functions
Hash Hash
Hash Functions Hash Functions
String Functions String Functions
Regular Expression Regular Expression
Regular Expression Functions Regular Expression Functions
Numerical Functions Numerical Functions
List Functions List Functions
User Defined Function User Defined Function
File Handling File Handling
Forums Ask Your Doubts
Feedback Feedback
 





Alternate Metacharacter in Perl


Tutorials Perl

Topic

What is Alternate Metacharacter in Perl?



Explanation

"|" specifies alternate patterns where matching of either one of them results in a match, usually it checks from left to right and the first one that is matching is taken."|" are used together with parentheses() to indicate the groupings preferred.

Example:
    #! C:\programfiles\perl\bin\perl
    print "content-type: text/html\n\n";
    if ("tom" =~ m/for|if|while/)
     {
      print "matched charatcer in tom!\n";
     } 
    else 
     {
      print "no match in tom!\n";
     }
    print "<br>";
    if ("abadc" =~ m/a(a|b|c)a/)
     {
      print "matched character in abadc!\n";
     }
    else 
     { 
      print "no match in abadc!\n";
     }
Result:
    no match in tom!
    matched character in abadc! 

In the above example the string "tom" is checked for match with "for", "if", "while", since it did'nt match, the string "abadc" is checked for match to have a string "aaa","aba", "aca" , since it contains the character "aba" it returns a match.






A Note
Simple introduction, basic CGI perl programming codes with examples. Do send your feedback or suggestions on this tutorial. This is a copyright content.

Other Links

web hosting