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
 





qr/STRING/ Function of Regular Expression in Perl


Tutorials Perl

Topic

What is qr/STRING/ Function in Perl?
How to compile a pattern using regular expression functions?


Explanation

The qr/STRING/ function is used to compile a pattern, rather a regular expression that can be used later.If there is a problem with the regular expression one can find it immediately.

Syntax:
     qr/STRING/;
Example to compile pattern:
    #! C:\programfiles\perl\bin\perl
    print "content-type: text/html\n\n";
    $pattern='^p';
    $re = qr/$pattern/;
    $string="people of this town";
    if($string =~ /$re/)
     {
      print "Matched Pattern, string starts with p";
     }
    else
     {
      print "String does'nt start with p";
     }
Result:
    Matched Pattern, string starts with p

In the above code we created a pattern to check whether a string starts with "p", which is stored in the variable "$re", then this variable can be embedded into another pattern or as standlone can be used anywhere. In the above code the pattern is matched to string then the the result is returned.






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