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 |
How would you ensure the re-use and maximum readability of your perl code?
what are the three groups involved in information sharing?
I have one question regarding to eval function. I know eval function is use for error checking but I am not able to understand below line. eval \'exec perl -S $0 ${1+\"$@\"}\' if 0; $0 for script name $@ set if error occur
Where the command line arguments are stored and if you want to read command-line arguments with Perl, how would you do that?
Explain chomp, chop, cpan, tk.
What is stdin in perl?
When would you not use Perl for a project?
What is use of ‘->’ symbol?
What package you use to create a windows services?
What are stdin, stdout and stderr?
What does `$result = f() .. g()' really return?
write a script to display mirror image of a entered value and also check whether Palindrome