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 |
Explain perl one-liner?
what is perl language?
What are the various advantages and disadvantages of perl?
What are the various file operations in perl. Explain with example.
What is caller function in perl?
Explain split function in perl?
Why to use perl?
What are the options that can be used to avoid logic errors in perl?
Explain what is lvalue?
How can you define “my” variables scope in Perl and how it is different from “local” variable scope?
Explain the difference between use and require?
How to get help for perl?