|
|
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.
|
|
|
|