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
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 |
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 |
What are the advantages and disadvantages of perl language?
Write a program that shows the distinction between child and parent process?
how to find a substring in a string without using substr built in functions, and print the substring found
What are perl array functions?
What do the symbols $ @ and % mean when prefixing a variable?
Comment on array slicing and range operator
what are the strategies followed for multiple form interaction in cgi programs?
How to print escaping characters inside a string in perl?
Explain split function in perl?
How do I sort a hash by the hash value?
What interface used in PERL to connect to database? How do you connect to database in Perl?
How to do comment in perl?