Programming Languages C Subjective
Mar 15, 2013

Write a perl script to find whether a given line of text is starting and ending with same word or not?

Detailed Explanation

Lets assume that the text to match is present in a file
say "data.txt".
Following program will print the line containing same
starting and ending word.

open(FILE,"data.txt") or die "cannot open file : $!";

while(<FILE>) {
if($_ =~ /^(\w+)\s+.*?\1$/) {
print "the line is $_ \n";
}
}

Discussion (0)

No comments yet. Be the first to share your thoughts!

Share Your Thoughts
Feedback