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
 





Match Begin,End Metacharacter


Tutorials Perl

Topic

What is Match Begin,End Metacharacter?



Explanation

The "^" metacharacter matches the beginning of the string, and "$" matches the end of the string.

Example:
    #! C:\programfiles\perl\bin\perl
    print "content-type: text/html\n\n";
    @fruits = ("orange", "guava", "grapes", "cherry", "berry");
    foreach $value(@fruits){  
    if($value =~ m/^g/)
     {
        print "$value has 'g' at the begining<br>";
     }
    } 
Result:
    guava has 'g' at the begining
    grapes has 'g' at the begining

In the above example the strings of an array is checked if the string is starting with the letter "g" and printed using the "^" character.

Example:
    #! C:\programfiles\perl\bin\perl
    print "content-type: text/html\n\n";
    @fruits = ("orange", "guava", "grapes", "cherry", "berry");
    foreach $value(@fruits){  
    if($value =~ m/y$/)
     {
        print "$value has 'y' at the end <br>";
     }
    } 
Result:
    cherry has 'y' at the end
    berry has 'y' at the end

In the above example the strings of the array "fruits" is checked for the letter 'y' at the end of each string and display the matched strings using the "$" character.






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