in reply to my script is not giving the result using last function
Should be:
if ($position == length($string))adding use strict; use warnings; to your code will help find such mistakes. The remainder of your problem is that if $char is not "a" then you break out of the while loop, at which point $position is still zero and not equal to the length of $string.
Consider basic debugging of your code, making use of http://learn.perl.org and the tutorials section.
There are easier ways of achieving your goal, however as a learning exercise I think you should at least figure out everything that's wrong with this approach.
|
|---|