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

What is the Common Gateway Interface?

2 Answers  


What is the use of now constructor in perl?

0 Answers  


What does next statement do in perl?

0 Answers  


How to connect to SQL server through Perl?

0 Answers  


what is the function that is used to identify how many characters are there in a string?

0 Answers  






What do the symbols $ @ and % mean when prefixing a variable?

1 Answers   Barclays,


Which functions in perl allows you to include a module file.

0 Answers  


Explain a tell function in perl?

0 Answers  


Explain lists in perl?

0 Answers  


How do I do fill_in_the_blank for each file in a directory?

0 Answers  


What does last statement do in perl?

0 Answers  


What is cpan in perl?

0 Answers  


Categories