Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

How many types of variable in perl?

0 Answers  


How do I send e-mail from a Perl/CGI program on a Unix system?

0 Answers  


What is the purpose of “_file_ literal” and “_line_ literal” in perl?

0 Answers  


What are arrays in perl?

0 Answers  


When does circular reference occur?

0 Answers  


Explain the difference between die and exit in perl?

0 Answers  


What does undef function in perl?

0 Answers  


Can you add two arrays together?

0 Answers  


How do you you check the return code of a command in perl?

0 Answers   HCL,


Why is it hard to call this function: sub y { "because" } ?

0 Answers  


Explain goto label?

0 Answers  


Explain goto label, goto name, and goto expr?

0 Answers  


Categories