Friday, October 17, 2008

Pattern Matching

There are some special read only variables
$&: matched part of the string
$`: preceding part
$’: following part

Example:
#!/usr/bin/perl -w

print("please Enter word to find out\n");
$a=;

chomp($a);

print("Please ENter the sentence \n");

while ($_=)
{
chomp($_);


if(/$a/)
{
print("\n The word is find in the sentence $_ \n");

print("The matching part is ".$&. "\n");

print("Before the matching : $`\n");

print("After the matching : $'");

}
}

No comments: