INTERVIEW QUESTIONS
PROGRAMMING LANGUAGES
PERL
DETAILS
Question: Write a script to reverse a string without using Perl's built in functions?
Answer: my $txt = 'Hello World'; my $len= length($txt); my $rev; while($len > 0){ $len--; $rev .= substr($txt,$len,1); } print $txt, ' - Reversed = ' , $rev;
|
Question:
Write a script to reverse a string without using Perl's built in functions?
Answer:
my $txt = 'Hello World'; my $len= length($txt); my $rev; while($len > 0){ $len--; $rev .= substr($txt,$len,1); } print $txt, ' - Reversed = ' , $rev; Source: CoolInterview.com
Answered by: sailas | Date: 5/3/2010
| Contact sailas
#!/usr/bin/perl my $str="MYSTRING"; my @arr= split(//, $str); @reverse_arr=reverse(@arr); $reverse_str = join('', @reverse_arr); print $reverse_str;
it prints- GNIRTSYM Source: CoolInterview.com
Answered by: Dinesh Sehgal | Date: 5/8/2010
| Contact Dinesh Sehgal
my $str="string"; my @arr=split(//,$str); for(my $i=scalar @arr; $i>=0;$i--) { print $arr[$i]; } Source: CoolInterview.com
Answered by: Valli | Date: 7/22/2010
| Contact Valli
$string = "Hello World"; $str = chop($string); $len = length($string);
for($i=0;$i<$len;$i++) { $c = chop($string); $str = $str.$c; } print "
Reverse = $str
"; Source: CoolInterview.com
Answered by: Sandeep | Date: 8/24/2010
| Contact Sandeep
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|