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
 





m// and binding Operator in Perl


Tutorials Perl

Topic

How to use m// and binding Operator?



Explanation
m// Operator:

The pattern to be matched for is placed in between the // slashes of "m//" operator, if any additional options are to be placed it can be added after the second forward slash like "m/***/s".

Quoted strings, you may use other symbols in place of //. However, if you use //, you may omit the prefix m.In case of heavily slashed patterns one can use other symbols like "|".

Example:
    #! C:\programfiles\perl\bin\perl
    print "content-type: text/html\n\n";
    if ("Capable" =~ m/able/) 
     {
      print "match!\n";
     } 
    else 
     {
       print "no match!\n";
     }
Result:
     match! 

In the above example the pattern "able" is checked in the string "capable" to find whether its present, since it exists it returns the result "match!".

Bind Operators:

If an expression combined using the "=~" or "!~" binding operators,that expression is searched for in the pattern specified. If the binding operator is missing "=~" is assumed as the binding operator and "$" is taken as the expression to be searched for.

In scalar context, the binding operator "=~" returns a true value if the expression matches the pattern, an empty string if it returns a false."!~" simply inverts so that if the expression matches the pattern a false value is returned, a true value otherwise. Therefore, the following two expressions are equivalent:

     !($expression =~ m/pattern/)
     $expression !~ m/pattern/





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