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

Answers were Sorted based on User's Feedback



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

Answer / 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

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

Answer / vipul dalwala

Above solution ($_ =~ /^(\w+)\s+.*?\1$/) does not work for
string like "vipul on allinterview.com onvipul";

I would suggest :

if( $_ =~ /^([^\s]+)(\s.*?)*\s\1$/ ) {
print "the line is $_ \n";
}

Is This Answer Correct ?    3 Yes 3 No

Post New Answer

More CGI Perl Interview Questions

Which operator in perl is used for the concatenation of two strings?

0 Answers  


Explain socket programming in perl?

0 Answers  


What are some of the key features of objects in perl?

0 Answers  


How to implement a stack in Perl?

0 Answers  


What is perl dbi?

0 Answers  


What does perl do in linux?

0 Answers  


How to disable the mod_perl from apache_server as i have used perlfect search on the site and its pagination is not working and the remedy is to disable the mod_perl.

0 Answers  


Explain splicing of arrays?

0 Answers  


Define perl scripting?

0 Answers  


How to compare two strings in perl?

0 Answers  


Explain the difference between use and require?

5 Answers   Aspire,


Explain chop?

0 Answers  


Categories