PDA

View Full Version : last char of a string


shuchi
02-26-03, 21:43
Hi again every1

I just wanetd to know if there is some way of checking the last character of a string....tht is checking it without finding the length and goin thru the whole string..
Is there a predefined function in perl tht returns the last char of a string without altering the string itself?
fr example if i have

$str="string."
i want to returm just "." and
$str should be still="string."

please let me know and thnx in advance frne hlpe provided

cheers
-s

Bernd Dulfer
02-27-03, 08:22
$last = substr($str, -1, 1)

shuchi
02-27-03, 21:19
thanx..that worked beautifully:)

-s