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

Answer Posted / guest

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";
}
}

Is This Answer Correct ?    5 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What does the’$_’ symbol mean?

583


What are different data types that perl supports. Elaborate on them.

563


What are the steps involved in configuring a server using cgi programming?

490


What is the purpose of goto expr statement?

486


what are the two ways to get private values inside a subroutine or block?

515






Remove the duplicate data from @array=(“perl”,”php”,”perl”,”asp”)

626


How can memory be managed in Perl?

558


Explain what is the scalar data and scalar variables in Perl?

575


Which has highest precedence in between list and terms? Explain?

450


What is cpan ? What are the modules coming under this?

520


Write a program to concatenate the $firststring and $secondstring and result of these strings should be separated by a single space.

644


How to find the length of an array in perl?

573


Explain goto expr?

503


What are the purpose of close(), getc() and read() functions?

488


How to convert arrays into a string in perl?

525